win32api/wtsapi32.go

75 lines
1.7 KiB
Go
Raw Permalink Normal View History

2019-03-07 11:39:54 +08:00
package win32api
import (
"syscall"
"unsafe"
)
func WTSQueryUserToken(SessionId DWORD, phToken *HANDLE) error {
WTGet, err := getProcAddr("wtsapi32.dll", "WTSQueryUserToken")
2019-03-07 11:39:54 +08:00
if err != nil {
return err
2019-03-07 11:39:54 +08:00
}
r, _, errno := syscall.Syscall(WTGet, 2, uintptr(SessionId), uintptr(unsafe.Pointer(phToken)), 0)
if r == 0 {
if errno != 0 {
return error(errno)
}
return syscall.EINVAL
}
return nil
}
func WTSEnumerateSessions(hServer HANDLE, Reserved, Version DWORD, ppSessionInfo *HANDLE, pCount *DWORD) error {
WT, err := getProcAddr("wtsapi32.dll", "WTSEnumerateSessionsW")
2019-03-07 11:39:54 +08:00
if err != nil {
return err
2019-03-07 11:39:54 +08:00
}
r, _, errno := syscall.Syscall6(WT, 5, uintptr(hServer), uintptr(Reserved), uintptr(Version), uintptr(unsafe.Pointer(ppSessionInfo)), uintptr(unsafe.Pointer(pCount)), 0)
2019-03-07 11:39:54 +08:00
if r == 0 {
if errno != 0 {
return error(errno)
}
return syscall.EINVAL
2019-03-07 11:39:54 +08:00
}
return nil
2019-03-07 11:39:54 +08:00
}
func WTSFreeMemory(pMemory HANDLE) error {
wfm, err := getProcAddr("wtsapi32.dll", "WTSFreeMemory")
2019-03-07 11:39:54 +08:00
if err != nil {
return err
2019-03-07 11:39:54 +08:00
}
syscall.Syscall(wfm, 1, uintptr(pMemory), 0, 0)
return nil
}
func WTSQuerySessionInformation(hServer HANDLE, sessionID DWORD, wtsInfoClass WTS_INFO_CLASS, ppBuffer *HANDLE, pBytesReturned *DWORD) error {
if ppBuffer == nil || pBytesReturned == nil {
return syscall.EINVAL
}
proc, err := getProcAddr("wtsapi32.dll", "WTSQuerySessionInformationW")
2019-03-07 11:39:54 +08:00
if err != nil {
return err
2019-03-07 11:39:54 +08:00
}
r, _, errno := syscall.Syscall6(
proc,
5,
uintptr(hServer),
uintptr(sessionID),
uintptr(wtsInfoClass),
uintptr(unsafe.Pointer(ppBuffer)),
uintptr(unsafe.Pointer(pBytesReturned)),
0,
)
2019-03-07 11:39:54 +08:00
if r == 0 {
if errno != 0 {
return error(errno)
}
return syscall.EINVAL
2019-03-07 11:39:54 +08:00
}
return nil
}