-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwindows.go
More file actions
42 lines (32 loc) · 746 Bytes
/
windows.go
File metadata and controls
42 lines (32 loc) · 746 Bytes
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
package main
import (
"fmt"
"unsafe"
"golang.org/x/sys/windows"
)
type tokenElevation struct {
TokenIsElevated uint32
}
func isElevated() (bool, error) {
var token windows.Token
err := windows.OpenProcessToken(windows.CurrentProcess(), windows.TOKEN_QUERY, &token)
if err != nil {
return false, fmt.Errorf("OpenProcessToken error: %v", err)
}
defer token.Close()
var (
elevation tokenElevation
elevationSize uint32
)
err = windows.GetTokenInformation(
token,
windows.TokenElevation,
(*byte)(unsafe.Pointer(&elevation)),
uint32(unsafe.Sizeof(elevation)),
&elevationSize,
)
if err != nil {
return false, fmt.Errorf("GetTokenInformation error: %v", err)
}
return elevation.TokenIsElevated != 0, nil
}