You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
win32api/kernel32.go

37 lines
994 B
Go

6 years ago
package win32api
import (
"errors"
"syscall"
)
func WTSGetActiveConsoleSessionId() (DWORD, error) {
kernel32, err := syscall.LoadLibrary("kernel32.dll")
if err != nil {
return 0, errors.New("Can't Load Kernel32 API")
}
defer syscall.FreeLibrary(kernel32)
WTGet, err := syscall.GetProcAddress(syscall.Handle(kernel32), "WTSGetActiveConsoleSessionId")
if err != nil {
return 0, errors.New("Can't Load WTSGetActiveConsoleSessionId API")
}
res, _, _ := syscall.Syscall(uintptr(WTGet), 0, 0, 0, 0)
return DWORD(res), nil
}
func CloseHandle(hObject HANDLE) error {
kernel32, err := syscall.LoadLibrary("kernel32.dll")
if err != nil {
return errors.New("Can't Load Kernel32 API")
}
defer syscall.FreeLibrary(kernel32)
CH, err := syscall.GetProcAddress(syscall.Handle(kernel32), "CloseHandle")
if err != nil {
return errors.New("Can't Load CloseHandle API")
}
if r, _, err := syscall.Syscall(uintptr(CH), 1, uintptr(hObject), 0, 0); r == 0 {
return err
}
return nil
}