package windows

import "github.com/cloudfoundry/gosigar/sys/windows"

Package windows contains various Windows system call.

Index

Constants

const (
	PROCESS_QUERY_LIMITED_INFORMATION uint32 = 0x1000
	PROCESS_VM_READ                   uint32 = 0x0010
)

Process-specific access rights. Others are declared in the syscall package. https://msdn.microsoft.com/en-us/library/windows/desktop/ms684880(v=vs.85).aspx

const (
	TH32CS_INHERIT      uint32 = 0x80000000 // Indicates that the snapshot handle is to be inheritable.
	TH32CS_SNAPHEAPLIST uint32 = 0x00000001 // Includes all heaps of the process specified in th32ProcessID in the snapshot.
	TH32CS_SNAPMODULE   uint32 = 0x00000008 // Includes all modules of the process specified in th32ProcessID in the snapshot.
	TH32CS_SNAPMODULE32 uint32 = 0x00000010 // Includes all 32-bit modules of the process specified in th32ProcessID in the snapshot when called from a 64-bit process.
	TH32CS_SNAPPROCESS  uint32 = 0x00000002 // Includes all processes in the system in the snapshot.
	TH32CS_SNAPTHREAD   uint32 = 0x00000004 // Includes all threads in the system in the snapshot.
)

Flags that can be used with CreateToolhelp32Snapshot.

const (
	ERROR_NOT_ALL_ASSIGNED syscall.Errno = 1300
)

Errors returned by AdjustTokenPrivileges.

const MAX_PATH = 260

MAX_PATH is the maximum length for a path in Windows. https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx

const (
	// SeDebugPrivilege is the name of the privilege used to debug programs.
	SeDebugPrivilege = "SeDebugPrivilege"
)

Functions

func CreateToolhelp32Snapshot

func CreateToolhelp32Snapshot(flags, pid uint32) (syscall.Handle, error)

CreateToolhelp32Snapshot takes a snapshot of the specified processes, as well as the heaps, modules, and threads used by these processes. https://msdn.microsoft.com/en-us/library/windows/desktop/ms682489(v=vs.85).aspx

func EnableTokenPrivileges

func EnableTokenPrivileges(token syscall.Token, privileges ...string) error

EnableTokenPrivileges enables the specified privileges in the given Token. The token must have TOKEN_ADJUST_PRIVILEGES access. If the token does not already contain the privilege it cannot be enabled.

func EnumProcesses

func EnumProcesses() ([]uint32, error)

EnumProcesses retrieves the process identifier for each process object in the system. This function can return a max of 65536 PIDs. If there are more processes than that then this will not return them all. https://msdn.microsoft.com/en-us/library/windows/desktop/ms682629(v=vs.85).aspx

func FiletimeToDuration

func FiletimeToDuration(ft *syscall.Filetime) time.Duration

FiletimeToDuration converts a Filetime to a time.Duration. Do not use this method to convert a Filetime to an actual clock time, for that use Filetime.Nanosecond().

func GetDiskFreeSpaceEx

func GetDiskFreeSpaceEx(directoryName string) (freeBytesAvailable, totalNumberOfBytes, totalNumberOfFreeBytes uint64, err error)

GetDiskFreeSpaceEx retrieves information about the amount of space that is available on a disk volume, which is the total amount of space, the total amount of free space, and the total amount of free space available to the user that is associated with the calling thread. https://msdn.microsoft.com/en-us/library/windows/desktop/aa364937(v=vs.85).aspx

func GetLogicalDriveStrings

func GetLogicalDriveStrings() ([]string, error)

GetLogicalDriveStrings returns a list of drives in the system. https://msdn.microsoft.com/en-us/library/windows/desktop/aa364975(v=vs.85).aspx

func GetProcessImageFileName

func GetProcessImageFileName(handle syscall.Handle) (string, error)

GetProcessImageFileName Retrieves the name of the executable file for the specified process. https://msdn.microsoft.com/en-us/library/windows/desktop/ms683217(v=vs.85).aspx

func GetSystemTimes

func GetSystemTimes() (idle, kernel, user time.Duration, err error)

GetSystemTimes retrieves system timing information. On a multiprocessor system, the values returned are the sum of the designated times across all processors. The returned kernel time does not include the system idle time. https://msdn.microsoft.com/en-us/library/windows/desktop/ms724400(v=vs.85).aspx

func GetTokenPrivileges

func GetTokenPrivileges(token syscall.Token) (map[string]Privilege, error)

GetTokenPrivileges returns a list of privileges associated with a token. The provided token must have at a minimum TOKEN_QUERY access. This is a wrapper around the GetTokenInformation function. https://msdn.microsoft.com/en-us/library/windows/desktop/aa446671(v=vs.85).aspx

func LookupPrivilegeName

func LookupPrivilegeName(systemName string, luid int64) (string, error)

LookupPrivilegeName looks up a privilege name given a LUID value.

Types

type DebugInfo

type DebugInfo struct {
	OSVersion    Version              // OS version info.
	Arch         string               // Architecture of the machine.
	NumCPU       int                  // Number of CPUs.
	User         User                 // User that this process is running as.
	ProcessPrivs map[string]Privilege // Privileges held by the process.
}

DebugInfo contains general debug info about the current process.

func GetDebugInfo

func GetDebugInfo() (*DebugInfo, error)

GetDebugInfo returns general debug info about the current process.

func (DebugInfo) String

func (d DebugInfo) String() string

type DriveType

type DriveType uint32

DriveType represents a type of drive (removable, fixed, CD-ROM, RAM disk, or network drive).

const (
	DRIVE_UNKNOWN DriveType = iota
	DRIVE_NO_ROOT_DIR
	DRIVE_REMOVABLE
	DRIVE_FIXED
	DRIVE_REMOTE
	DRIVE_CDROM
	DRIVE_RAMDISK
)

Drive types as returned by GetDriveType. https://msdn.microsoft.com/en-us/library/windows/desktop/aa364939(v=vs.85).aspx

func GetDriveType

func GetDriveType(rootPathName string) (DriveType, error)

GetDriveType Determines whether a disk drive is a removable, fixed, CD-ROM, RAM disk, or network drive. A trailing backslash is required on the rootPathName. https://msdn.microsoft.com/en-us/library/windows/desktop/aa364939

func (DriveType) String

func (dt DriveType) String() string

type MemoryStatusEx

type MemoryStatusEx struct {
	MemoryLoad           uint32
	TotalPhys            uint64
	AvailPhys            uint64
	TotalPageFile        uint64
	AvailPageFile        uint64
	TotalVirtual         uint64
	AvailVirtual         uint64
	AvailExtendedVirtual uint64
	// contains filtered or unexported fields
}

MemoryStatusEx is an equivalent representation of MEMORYSTATUSEX in the Windows API. It contains information about the current state of both physical and virtual memory, including extended memory. https://msdn.microsoft.com/en-us/library/windows/desktop/aa366770

func GlobalMemoryStatusEx

func GlobalMemoryStatusEx() (MemoryStatusEx, error)

GlobalMemoryStatusEx retrieves information about the system's current usage of both physical and virtual memory. https://msdn.microsoft.com/en-us/library/windows/desktop/aa366589(v=vs.85).aspx

type Privilege

type Privilege struct {
	LUID             int64  `json:"-"` // Locally unique identifier (guaranteed only until the system is restarted).
	Name             string `json:"-"`
	EnabledByDefault bool   `json:"enabled_by_default,omitempty"`
	Enabled          bool   `json:"enabled"`
	Removed          bool   `json:"removed,omitempty"`
	Used             bool   `json:"used,omitempty"`
}

Privilege contains information about a single privilege associated with a Token.

func (Privilege) String

func (p Privilege) String() string

type ProcessBasicInformation

type ProcessBasicInformation struct {
	ExitStatus                   uint
	PebBaseAddress               uintptr
	AffinityMask                 uint
	BasePriority                 uint
	UniqueProcessID              uint
	InheritedFromUniqueProcessID uint
}

ProcessBasicInformation is an equivalent representation of PROCESS_BASIC_INFORMATION in the Windows API. https://msdn.microsoft.com/en-us/library/windows/desktop/ms684280(v=vs.85).aspx

func NtQueryProcessBasicInformation

func NtQueryProcessBasicInformation(handle syscall.Handle) (ProcessBasicInformation, error)

NtQueryProcessBasicInformation queries basic information about the process associated with the given handle (provided by OpenProcess). It uses the NtQueryInformationProcess function to collect the data. https://msdn.microsoft.com/en-us/library/windows/desktop/ms684280(v=vs.85).aspx

type ProcessEntry32

type ProcessEntry32 struct {
	CntUsage          uint32
	ProcessID         uint32
	DefaultHeapID     uintptr
	ModuleID          uint32
	CntThreads        uint32
	ParentProcessID   uint32
	PriorityClassBase int32
	Flags             uint32
	// contains filtered or unexported fields
}

ProcessEntry32 is an equivalent representation of PROCESSENTRY32 in the Windows API. It contains a process's information. Do not modify or reorder. https://msdn.microsoft.com/en-us/library/windows/desktop/ms684839(v=vs.85).aspx

func Process32First

func Process32First(handle syscall.Handle) (ProcessEntry32, error)

Process32First retrieves information about the first process encountered in a system snapshot. https://msdn.microsoft.com/en-us/library/windows/desktop/ms684834

func Process32Next

func Process32Next(handle syscall.Handle) (ProcessEntry32, error)

Process32Next retrieves information about the next process recorded in a system snapshot. When there are no more processes to iterate then syscall.ERROR_NO_MORE_FILES is returned (use errors.Cause() to unwrap). https://msdn.microsoft.com/en-us/library/windows/desktop/ms684836

func (ProcessEntry32) ExeFile

func (p ProcessEntry32) ExeFile() string

ExeFile returns the name of the executable file for the process. It does not contain the full path.

func (ProcessEntry32) String

func (p ProcessEntry32) String() string

type ProcessMemoryCountersEx

type ProcessMemoryCountersEx struct {
	PageFaultCount             uint32
	PeakWorkingSetSize         uintptr
	WorkingSetSize             uintptr
	QuotaPeakPagedPoolUsage    uintptr
	QuotaPagedPoolUsage        uintptr
	QuotaPeakNonPagedPoolUsage uintptr
	QuotaNonPagedPoolUsage     uintptr
	PagefileUsage              uintptr
	PeakPagefileUsage          uintptr
	PrivateUsage               uintptr
	// contains filtered or unexported fields
}

ProcessMemoryCountersEx is an equivalent representation of PROCESS_MEMORY_COUNTERS_EX in the Windows API. https://msdn.microsoft.com/en-us/library/windows/desktop/ms684874(v=vs.85).aspx

func GetProcessMemoryInfo

func GetProcessMemoryInfo(handle syscall.Handle) (ProcessMemoryCountersEx, error)

GetProcessMemoryInfo retrieves information about the memory usage of the specified process. https://msdn.microsoft.com/en-us/library/windows/desktop/ms683219(v=vs.85).aspx

type SystemProcessorPerformanceInformation

type SystemProcessorPerformanceInformation struct {
	IdleTime   time.Duration // Amount of time spent idle.
	KernelTime time.Duration // Kernel time does NOT include time spent in idle.
	UserTime   time.Duration // Amount of time spent executing in user mode.
}

SystemProcessorPerformanceInformation contains CPU performance information for a single CPU.

func NtQuerySystemProcessorPerformanceInformation

func NtQuerySystemProcessorPerformanceInformation() ([]SystemProcessorPerformanceInformation, error)

NtQuerySystemProcessorPerformanceInformation queries CPU performance information for each CPU. It uses the NtQuerySystemInformation function to collect the SystemProcessorPerformanceInformation. https://msdn.microsoft.com/en-us/library/windows/desktop/ms724509(v=vs.85).aspx

type User

type User struct {
	SID     string
	Account string
	Domain  string
	Type    uint32
}

User represent the information about a Windows account.

func GetTokenUser

func GetTokenUser(token syscall.Token) (User, error)

GetTokenUser returns the User associated with the given Token.

func (User) String

func (u User) String() string

type Version

type Version struct {
	Major int
	Minor int
	Build int
}

Version identifies a Windows version by major, minor, and build number.

func GetWindowsVersion

func GetWindowsVersion() Version

GetWindowsVersion returns the Windows version information. Applications not manifested for Windows 8.1 or Windows 10 will return the Windows 8 OS version value (6.2).

For a table of version numbers see: https://msdn.microsoft.com/en-us/library/windows/desktop/ms724833(v=vs.85).aspx

func (Version) IsWindowsVistaOrGreater

func (v Version) IsWindowsVistaOrGreater() bool

IsWindowsVistaOrGreater returns true if the Windows version is Vista or greater.

Source Files

doc.go ntquery.go privileges.go syscall_windows.go version.go zsyscall_windows.go

Version
v1.3.92 (latest)
Published
May 7, 2025
Platform
windows/amd64
Imports
13 packages
Last checked
14 hours ago

Tools for package owners.