From f534f020af5b288f9c944c32acf23fccc4855ef8 Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Sat, 3 Oct 2020 10:43:38 -0700 Subject: [PATCH] fix: correctly show admin icon --- environment_windows.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/environment_windows.go b/environment_windows.go index 746aa898..56e300fe 100755 --- a/environment_windows.go +++ b/environment_windows.go @@ -1,13 +1,12 @@ package main import ( - "log" - "golang.org/x/sys/windows" ) func (env *environment) isRunningAsRoot() bool { var sid *windows.SID + // Although this looks scary, it is directly copied from the // official windows documentation. The Go API for this is a // direct wrap around the official C++ API. @@ -20,17 +19,19 @@ func (env *environment) isRunningAsRoot() bool { 0, 0, 0, 0, 0, 0, &sid) if err != nil { - log.Fatalf("SID Error: %s", err) return false } + defer windows.FreeSid(sid) // This appears to cast a null pointer so I'm not sure why this // works, but this guy says it does and it Works for Me™: // https://github.com/golang/go/issues/28804#issuecomment-438838144 token := windows.Token(0) + member, err := token.IsMember(sid) if err != nil { return false } - return member && token.IsElevated() + + return member }