-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsystem_windows.go
More file actions
59 lines (49 loc) · 1.37 KB
/
system_windows.go
File metadata and controls
59 lines (49 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package util
import (
"fmt"
"syscall"
"github.com/MiyamuraMiyako/go-util/introp"
)
type LUID struct {
LowPart uint32
HighPart int32
}
type LUID_AND_ATTRIBUTES struct {
Luid LUID
Attributes uint32
}
type TokPriv1Luid struct {
PrivilegeCount uint32
Privileges [1]LUID_AND_ATTRIBUTES
}
//PowerOff CAN NOT USE YET!!!!
func PowerOff(force, reboot bool) {
advapi32 := syscall.NewLazyDLL("advapi32.dll")
user32 := syscall.NewLazyDLL("user32.dll")
kernel32 := syscall.NewLazyDLL("kernel32.dll")
LookupPrivilegeValue := advapi32.NewProc("LookupPrivilegeValueW")
AdjustTokenPrivileges := advapi32.NewProc("AdjustTokenPrivileges")
ExitWindowsEx := user32.NewProc("ExitWindowsEx")
GetCurrentProcess := kernel32.NewProc("GetCurrentProcess")
r1, _, err := GetCurrentProcess.Call()
fmt.Println(err.Error())
var tk syscall.Token
syscall.OpenProcessToken((syscall.Handle)(r1), 40, &tk)
laa := LUID_AND_ATTRIBUTES{
Luid: LUID{},
Attributes: 2}
toPrivLuid := TokPriv1Luid{
PrivilegeCount: 1,
Privileges: [1]LUID_AND_ATTRIBUTES{laa}}
LookupPrivilegeValue.Call(0, introp.ToPtr("SeShutdownPrivilege"), introp.ToPtr(toPrivLuid.Privileges[0].Luid))
AdjustTokenPrivileges.Call((uintptr)(tk), 0, introp.ToPtr(toPrivLuid), 0, 0, 0)
if reboot {
flg := 6
if force {
flg = 18
}
ExitWindowsEx.Call(uintptr(flg), 0)
} else {
ExitWindowsEx.Call(1, 0)
}
}