mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-02-21 02:55:37 -08:00
fix: correctly show admin icon
This commit is contained in:
parent
c99d7585e7
commit
f534f020af
|
@ -1,13 +1,12 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
|
||||||
|
|
||||||
"golang.org/x/sys/windows"
|
"golang.org/x/sys/windows"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (env *environment) isRunningAsRoot() bool {
|
func (env *environment) isRunningAsRoot() bool {
|
||||||
var sid *windows.SID
|
var sid *windows.SID
|
||||||
|
|
||||||
// Although this looks scary, it is directly copied from the
|
// Although this looks scary, it is directly copied from the
|
||||||
// official windows documentation. The Go API for this is a
|
// official windows documentation. The Go API for this is a
|
||||||
// direct wrap around the official C++ API.
|
// direct wrap around the official C++ API.
|
||||||
|
@ -20,17 +19,19 @@ func (env *environment) isRunningAsRoot() bool {
|
||||||
0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0,
|
||||||
&sid)
|
&sid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("SID Error: %s", err)
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
defer windows.FreeSid(sid)
|
||||||
|
|
||||||
// This appears to cast a null pointer so I'm not sure why this
|
// 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™:
|
// works, but this guy says it does and it Works for Me™:
|
||||||
// https://github.com/golang/go/issues/28804#issuecomment-438838144
|
// https://github.com/golang/go/issues/28804#issuecomment-438838144
|
||||||
token := windows.Token(0)
|
token := windows.Token(0)
|
||||||
|
|
||||||
member, err := token.IsMember(sid)
|
member, err := token.IsMember(sid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return member && token.IsElevated()
|
|
||||||
|
return member
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue