Documentation
¶
Index ¶
- Constants
- func AppendMenu(menu uintptr, flags, idNewItem uintptr, text string) error
- func AssignProcessToJobObject(job, proc windows.Handle) error
- func CloseHandleSafe(h windows.Handle)
- func CollectQueryData(query PdhQuery) error
- func CreateJobObject() (windows.Handle, error)
- func CreatePopupMenu() uintptr
- func CreateToolhelp32Snapshot(flags, pid uint32) (windows.Handle, error)
- func CreateWindowEx(exStyle uint32, className, windowName *uint16, style uint32, ...) (uintptr, error)
- func DefWindowProc(hwnd, msg, wParam, lParam uintptr) uintptr
- func DestroyMenu(menu uintptr)
- func DestroyWindow(hwnd uintptr)
- func DispatchMessage(msg *MSG) uintptr
- func FileTimeToUnix(ft FILETIME) int64
- func GetDiskFreeSpaceEx(path string) (freeAvail, totalBytes, totalFree uint64, err error)
- func GetDriveType(root string) uint32
- func GetFormattedCounterArrayDouble(counter PdhCounter) (map[string]float64, error)
- func GetLogicalDriveStrings() ([]string, error)
- func GetMessage(msg *MSG, hwnd uintptr) int32
- func GetPriorityClass(h windows.Handle) (uint32, error)
- func GetVolumeInformation(root string) (label, fsName string)
- func IsProcessCritical(h windows.Handle) (bool, error)
- func LoadCursor(name uintptr) uintptr
- func LoadIcon(name uintptr) uintptr
- func OpenProcessHandle(access uint32, pid uint32) (windows.Handle, error)
- func OpenThreadHandle(access uint32, threadID uint32) (windows.Handle, error)
- func PostMessage(hwnd uintptr, msg uint32, wParam, lParam uintptr)
- func PostQuitMessage(exitCode int32)
- func Process32First(snap windows.Handle, entry *PROCESSENTRY32W) error
- func Process32Next(snap windows.Handle, entry *PROCESSENTRY32W) error
- func QueryFullProcessImageName(h windows.Handle) (string, error)
- func RegReadDWORD(rootKey uintptr, subKey, value string) (uint32, error)
- func RegReadQWORD(rootKey uintptr, subKey, value string) (uint64, error)
- func RegReadString(rootKey uintptr, subKey, value string) (string, error)
- func RegisterClassEx(c *WNDCLASSEXW) (uint16, error)
- func ResumeThread(h windows.Handle) (uint32, error)
- func SetForegroundWindow(hwnd uintptr)
- func SetInformationJobObject(job windows.Handle, infoClass uint32, info unsafe.Pointer, length uint32) error
- func SetPriorityClass(h windows.Handle, class uint32) error
- func SetProcessAffinityMask(h windows.Handle, mask uintptr) error
- func SetTipString(dst []uint16, s string)
- func ShellExecute(verb, file, params, dir string, show int32) error
- func ShellNotifyIcon(message uint32, nid *NOTIFYICONDATAW) error
- func SuspendThread(h windows.Handle) (uint32, error)
- func TerminateProcessHandle(h windows.Handle, exitCode uint32) error
- func Thread32First(snap windows.Handle, te *THREADENTRY32) error
- func Thread32Next(snap windows.Handle, te *THREADENTRY32) error
- func TrackPopupMenu(menu uintptr, flags uint32, x, y int32, hwnd uintptr) uintptr
- func TranslateMessage(msg *MSG)
- type FILETIME
- type IO_COUNTERS
- type IfRow2
- type JOBOBJECT_BASIC_LIMIT_INFORMATION
- type JOBOBJECT_CPU_RATE_CONTROL_INFORMATION
- type JOBOBJECT_EXTENDED_LIMIT_INFORMATION
- type MEMORYSTATUSEX
- type MIB_TCP6ROW_OWNER_PID
- type MIB_TCPROW_OWNER_PID
- type MIB_UDP6ROW_OWNER_PID
- type MIB_UDPROW_OWNER_PID
- type MSG
- type NOTIFYICONDATAW
- type POINT
- type PROCESSENTRY32W
- type PROCESS_MEMORY_COUNTERS_EX
- type PdhCounter
- type PdhQuery
- type SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
- type THREADENTRY32
- type WNDCLASSEXW
Constants ¶
const ( HKEY_LOCAL_MACHINE = 0x80000002 KEY_READ = 0x20019 )
HKEY values.
const ( MIB_TCP_STATE_CLOSED = 1 MIB_TCP_STATE_LISTEN = 2 MIB_TCP_STATE_SYN_SENT = 3 MIB_TCP_STATE_SYN_RCVD = 4 MIB_TCP_STATE_ESTAB = 5 MIB_TCP_STATE_FIN_WAIT1 = 6 MIB_TCP_STATE_FIN_WAIT2 = 7 MIB_TCP_STATE_CLOSE_WAIT = 8 MIB_TCP_STATE_CLOSING = 9 MIB_TCP_STATE_LAST_ACK = 10 MIB_TCP_STATE_TIME_WAIT = 11 MIB_TCP_STATE_DELETE_TCB = 12 )
TCP states (MIB_TCP_STATE_*).
const ( TCP_TABLE_OWNER_PID_ALL = 5 UDP_TABLE_OWNER_PID = 1 )
TCP_TABLE_CLASS values for GetExtendedTcpTable.
const ( TH32CS_SNAPPROCESS = 0x00000002 TH32CS_SNAPTHREAD = 0x00000004 )
CreateToolhelp32Snapshot flags.
const ( JobObjectBasicLimitInformation = 2 JobObjectExtendedLimitInformation = 9 JobObjectCpuRateControlInformation = 15 )
Job Object information class values.
const ( JOB_OBJECT_CPU_RATE_CONTROL_ENABLE = 0x00000001 JOB_OBJECT_CPU_RATE_CONTROL_HARD_CAP = 0x00000004 )
Job Object CPU rate control flags.
const ( IDLE_PRIORITY_CLASS = 0x00000040 BELOW_NORMAL_PRIORITY_CLASS = 0x00004000 NORMAL_PRIORITY_CLASS = 0x00000020 ABOVE_NORMAL_PRIORITY_CLASS = 0x00008000 HIGH_PRIORITY_CLASS = 0x00000080 REALTIME_PRIORITY_CLASS = 0x00000100 )
Priority class values.
const ( NIM_ADD = 0x00000000 NIM_MODIFY = 0x00000001 NIM_DELETE = 0x00000002 NIF_MESSAGE = 0x00000001 NIF_ICON = 0x00000002 NIF_TIP = 0x00000004 NIF_INFO = 0x00000010 NIIF_INFO = 0x00000001 NIIF_WARNING = 0x00000002 NIIF_ERROR = 0x00000003 )
Shell_NotifyIcon flags.
const ( WM_USER = 0x0400 WM_TRAYICON = WM_USER + 1 WM_LBUTTONUP = 0x0202 WM_LBUTTONDBLCLK = 0x0203 WM_RBUTTONUP = 0x0205 WM_COMMAND = 0x0111 WM_DESTROY = 0x0002 )
Tray window message constants.
const ( DRIVE_UNKNOWN = 0 DRIVE_REMOVABLE = 2 DRIVE_FIXED = 3 DRIVE_REMOTE = 4 )
Drive types.
const ( AF_INET = 2 AF_INET6 = 23 )
Address families.
const ( IDI_APPLICATION uintptr = 32512 IDC_ARROW uintptr = 32512 )
Stock icons / cursors.
const ( TPM_LEFTALIGN = 0x0000 TPM_RIGHTBUTTON = 0x0002 TPM_RETURNCMD = 0x0100 )
TPM constants.
const HWND_MESSAGE = ^uintptr(2) //nolint:gocritic // 0xFFFFFFFD
HWND_MESSAGE for message-only windows.
const (
JOB_OBJECT_LIMIT_PROCESS_MEMORY = 0x00000100
)
Job Object limit flags.
const (
SW_SHOWNORMAL = 1
)
ShowWindow / ShellExecute constants.
const SystemProcessorPerformanceInformation = 8
Variables ¶
This section is empty.
Functions ¶
func AppendMenu ¶
AppendMenu adds an item to a menu.
func AssignProcessToJobObject ¶
AssignProcessToJobObject assigns a process to a job.
func CloseHandleSafe ¶
CloseHandleSafe closes a Windows handle ignoring errors.
func CollectQueryData ¶ added in v0.2.0
CollectQueryData samples all counters attached to the PDH query.
func CreateJobObject ¶
CreateJobObject creates an unnamed Job Object.
func CreateToolhelp32Snapshot ¶
CreateToolhelp32Snapshot creates a snapshot of system processes/threads/modules.
func CreateWindowEx ¶
func CreateWindowEx(exStyle uint32, className, windowName *uint16, style uint32, x, y, width, height int32, parent uintptr, menu, instance uintptr, param unsafe.Pointer) (uintptr, error)
CreateWindowEx creates a window.
func DefWindowProc ¶
DefWindowProc calls the default window procedure.
func DispatchMessage ¶
DispatchMessage dispatches a message to a window procedure.
func FileTimeToUnix ¶
FileTimeToUnix converts a Win32 FILETIME to a Unix timestamp (seconds).
func GetDiskFreeSpaceEx ¶
GetDiskFreeSpaceEx retrieves available, total, and free space on a drive.
func GetDriveType ¶
GetDriveType returns the drive type (DRIVE_*) for a root path.
func GetFormattedCounterArrayDouble ¶ added in v0.2.0
func GetFormattedCounterArrayDouble(counter PdhCounter) (map[string]float64, error)
GetFormattedCounterArrayDouble returns the cooked values for a wildcard counter.
func GetLogicalDriveStrings ¶
GetLogicalDriveStrings returns a list of drive root paths.
func GetMessage ¶
GetMessage retrieves a message from the calling thread's queue.
func GetPriorityClass ¶
GetPriorityClass returns a process's priority class.
func GetVolumeInformation ¶
GetVolumeInformation retrieves a drive's volume name and filesystem.
func IsProcessCritical ¶
IsProcessCritical reports whether a process is marked critical.
func LoadCursor ¶
LoadCursor loads a stock cursor (e.g., IDC_ARROW).
func OpenProcessHandle ¶
OpenProcessHandle opens a process and returns a handle.
func OpenThreadHandle ¶
OpenThreadHandle opens a thread and returns a handle.
func PostMessage ¶
PostMessage posts a message into the message queue of the specified window.
func PostQuitMessage ¶
func PostQuitMessage(exitCode int32)
PostQuitMessage posts a WM_QUIT message.
func Process32First ¶
func Process32First(snap windows.Handle, entry *PROCESSENTRY32W) error
Process32First retrieves the first process entry from a snapshot.
func Process32Next ¶
func Process32Next(snap windows.Handle, entry *PROCESSENTRY32W) error
Process32Next retrieves the next process entry.
func QueryFullProcessImageName ¶
QueryFullProcessImageName retrieves a process's full executable path.
func RegReadDWORD ¶
RegReadDWORD reads a DWORD registry value.
func RegReadQWORD ¶ added in v0.2.0
RegReadQWORD reads a QWORD registry value.
func RegReadString ¶
RegReadString reads a string registry value.
func RegisterClassEx ¶
func RegisterClassEx(c *WNDCLASSEXW) (uint16, error)
RegisterClassEx registers a window class.
func ResumeThread ¶
ResumeThread resumes a thread; returns previous suspend count.
func SetForegroundWindow ¶
func SetForegroundWindow(hwnd uintptr)
SetForegroundWindow brings the specified window to the foreground.
func SetInformationJobObject ¶
func SetInformationJobObject(job windows.Handle, infoClass uint32, info unsafe.Pointer, length uint32) error
SetInformationJobObject sets information on a Job Object.
func SetPriorityClass ¶
SetPriorityClass sets a process's priority class.
func SetProcessAffinityMask ¶
SetProcessAffinityMask sets a process affinity mask.
func SetTipString ¶
SetTipString writes text into a fixed-size uint16 array, NUL-terminating.
func ShellExecute ¶
ShellExecute opens or launches a file or URL.
func ShellNotifyIcon ¶
func ShellNotifyIcon(message uint32, nid *NOTIFYICONDATAW) error
ShellNotifyIcon adds, modifies, or removes a notification area icon.
func SuspendThread ¶
SuspendThread suspends a thread; returns previous suspend count.
func TerminateProcessHandle ¶
TerminateProcessHandle terminates a process via handle.
func Thread32First ¶
func Thread32First(snap windows.Handle, te *THREADENTRY32) error
Thread32First retrieves the first thread from a snapshot.
func Thread32Next ¶
func Thread32Next(snap windows.Handle, te *THREADENTRY32) error
Thread32Next retrieves the next thread.
func TrackPopupMenu ¶
TrackPopupMenu displays a popup menu.
func TranslateMessage ¶
func TranslateMessage(msg *MSG)
TranslateMessage translates virtual-key messages.
Types ¶
type FILETIME ¶
FILETIME is Win32 FILETIME (100ns ticks since 1601-01-01).
func GetProcessTimes ¶
GetProcessTimes retrieves a process's creation/exit/kernel/user times.
func GetSystemTimes ¶
GetSystemTimes retrieves system idle/kernel/user FILETIMEs.
type IO_COUNTERS ¶
type IO_COUNTERS struct {
ReadOperationCount uint64
WriteOperationCount uint64
OtherOperationCount uint64
ReadTransferCount uint64
WriteTransferCount uint64
OtherTransferCount uint64
}
IO_COUNTERS matches Win32 IO_COUNTERS.
func GetProcessIoCounters ¶
func GetProcessIoCounters(h windows.Handle) (*IO_COUNTERS, error)
GetProcessIoCounters retrieves a process's I/O counters.
type IfRow2 ¶
type IfRow2 struct {
Index uint32
Alias string
Description string
OperStatus uint32
Type uint32
SpeedRx uint64
SpeedTx uint64
InOctets uint64
OutOctets uint64
InUcastPkts uint64
OutUcastPkts uint64
InErrors uint64
OutErrors uint64
}
IfRow2 holds the fields we care about parsed from MIB_IF_ROW2.
func GetIfTable2 ¶
GetIfTable2 returns the system network interface table. We let the Win32 API allocate a MIB_IF_TABLE2 buffer, walk the rows at their documented offsets, then free the buffer via FreeMibTable.
tablePtr is declared as unsafe.Pointer (not uintptr) so vet's unsafeptr analyzer is satisfied: we never do arithmetic on a uintptr and convert it back — all offsetting goes through unsafe.Add.
type JOBOBJECT_BASIC_LIMIT_INFORMATION ¶
type JOBOBJECT_BASIC_LIMIT_INFORMATION struct {
PerProcessUserTimeLimit int64
PerJobUserTimeLimit int64
LimitFlags uint32
MinimumWorkingSetSize uintptr
MaximumWorkingSetSize uintptr
ActiveProcessLimit uint32
Affinity uintptr
PriorityClass uint32
SchedulingClass uint32
}
JOBOBJECT_BASIC_LIMIT_INFORMATION matches Win32 struct.
type JOBOBJECT_CPU_RATE_CONTROL_INFORMATION ¶
JOBOBJECT_CPU_RATE_CONTROL_INFORMATION matches Win32 struct.
type JOBOBJECT_EXTENDED_LIMIT_INFORMATION ¶
type JOBOBJECT_EXTENDED_LIMIT_INFORMATION struct {
BasicLimitInformation JOBOBJECT_BASIC_LIMIT_INFORMATION
IoInfo IO_COUNTERS
ProcessMemoryLimit uintptr
JobMemoryLimit uintptr
PeakProcessMemoryUsed uintptr
PeakJobMemoryUsed uintptr
}
JOBOBJECT_EXTENDED_LIMIT_INFORMATION matches Win32 struct.
type MEMORYSTATUSEX ¶
type MEMORYSTATUSEX struct {
Length uint32
MemoryLoad uint32
TotalPhys uint64
AvailPhys uint64
TotalPageFile uint64
AvailPageFile uint64
TotalVirtual uint64
AvailVirtual uint64
AvailExtendedVirtual uint64
}
MEMORYSTATUSEX matches Win32 MEMORYSTATUSEX.
func GlobalMemoryStatusEx ¶
func GlobalMemoryStatusEx() (*MEMORYSTATUSEX, error)
GlobalMemoryStatusEx retrieves system memory information.
type MIB_TCP6ROW_OWNER_PID ¶
type MIB_TCP6ROW_OWNER_PID struct {
LocalAddr [16]byte
LocalScopeId uint32
LocalPort uint32
RemoteAddr [16]byte
RemoteScopeId uint32
RemotePort uint32
State uint32
OwningPid uint32
}
MIB_TCP6ROW_OWNER_PID matches Win32 IPv6 TCP row.
func GetTcp6Table ¶
func GetTcp6Table() ([]MIB_TCP6ROW_OWNER_PID, error)
GetTcp6Table returns IPv6 TCP rows with owning PIDs.
type MIB_TCPROW_OWNER_PID ¶
type MIB_TCPROW_OWNER_PID struct {
State uint32
LocalAddr uint32
LocalPort uint32
RemoteAddr uint32
RemotePort uint32
OwningPid uint32
}
MIB_TCPROW_OWNER_PID matches Win32 IPv4 TCP row.
func GetTcp4Table ¶
func GetTcp4Table() ([]MIB_TCPROW_OWNER_PID, error)
GetTcp4Table returns IPv4 TCP rows with owning PIDs.
type MIB_UDP6ROW_OWNER_PID ¶
type MIB_UDP6ROW_OWNER_PID struct {
LocalAddr [16]byte
LocalScopeId uint32
LocalPort uint32
OwningPid uint32
}
MIB_UDP6ROW_OWNER_PID matches Win32 IPv6 UDP row.
func GetUdp6Table ¶
func GetUdp6Table() ([]MIB_UDP6ROW_OWNER_PID, error)
GetUdp6Table returns IPv6 UDP rows with owning PIDs.
type MIB_UDPROW_OWNER_PID ¶
MIB_UDPROW_OWNER_PID matches Win32 IPv4 UDP row.
func GetUdp4Table ¶
func GetUdp4Table() ([]MIB_UDPROW_OWNER_PID, error)
GetUdp4Table returns IPv4 UDP rows with owning PIDs.
type NOTIFYICONDATAW ¶
type NOTIFYICONDATAW struct {
Size uint32
Wnd uintptr
ID uint32
Flags uint32
CallbackMessage uint32
Icon uintptr
Tip [128]uint16
State uint32
StateMask uint32
Info [256]uint16
Union uint32
InfoTitle [64]uint16
InfoFlags uint32
GuidItem [16]byte
BalloonIcon uintptr
}
NOTIFYICONDATAW matches Win32 NOTIFYICONDATAW.
type PROCESSENTRY32W ¶
type PROCESSENTRY32W struct {
Size uint32
Usage uint32
ProcessID uint32
DefaultHeapID uintptr
ModuleID uint32
Threads uint32
ParentProcessID uint32
PriClassBase int32
Flags uint32
ExeFile [260]uint16
}
PROCESSENTRY32W matches Win32 PROCESSENTRY32W.
type PROCESS_MEMORY_COUNTERS_EX ¶
type PROCESS_MEMORY_COUNTERS_EX struct {
CB uint32
PageFaultCount uint32
PeakWorkingSetSize uintptr
WorkingSetSize uintptr
QuotaPeakPagedPoolUsage uintptr
QuotaPagedPoolUsage uintptr
QuotaPeakNonPagedPoolUsage uintptr
QuotaNonPagedPoolUsage uintptr
PagefileUsage uintptr
PeakPagefileUsage uintptr
PrivateUsage uintptr
}
PROCESS_MEMORY_COUNTERS_EX matches Win32 PROCESS_MEMORY_COUNTERS_EX.
func GetProcessMemoryInfo ¶
func GetProcessMemoryInfo(h windows.Handle) (*PROCESS_MEMORY_COUNTERS_EX, error)
GetProcessMemoryInfo retrieves a process's memory counters.
type PdhCounter ¶ added in v0.2.0
type PdhCounter uintptr
PdhCounter is an opaque PDH counter handle.
func AddEnglishCounter ¶ added in v0.2.0
func AddEnglishCounter(query PdhQuery, path string) (PdhCounter, error)
AddEnglishCounter registers a wildcard or concrete counter path with a query.
type PdhQuery ¶ added in v0.2.0
type PdhQuery uintptr
PdhQuery is an opaque PDH query handle.
func OpenPdhQuery ¶ added in v0.2.0
OpenPdhQuery opens a PDH query for subsequent counter registration.
type SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION ¶
type SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION struct {
IdleTime int64
KernelTime int64
UserTime int64
Reserved1 [2]int64
Reserved2 uint32
}
SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION (NtQuerySystemInformation class 8).
func QueryProcessorPerformance ¶
func QueryProcessorPerformance(numCPU int) ([]SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION, error)
QueryProcessorPerformance returns per-logical-processor performance info.