33 lines
656 B
Go
33 lines
656 B
Go
package installer
|
|
|
|
import "os/user"
|
|
|
|
// IsAdmin returns true if the user can be determined to be an admin
|
|
// and false otherwise (errs on the side of non-admin).
|
|
func IsAdmin() bool {
|
|
u, err := user.Current()
|
|
if nil != err {
|
|
return false
|
|
}
|
|
|
|
// https://support.microsoft.com/en-us/help/243330/well-known-security-identifiers-in-windows-operating-systems
|
|
// not quite, but close enough for now
|
|
// BUILTIN\ADMINISTRATORS
|
|
if "S-1-5-32-544" == u.Uid || "S-1-5-32-544" == u.Gid {
|
|
return true
|
|
}
|
|
|
|
ids, err := u.GroupIds()
|
|
if nil != err {
|
|
return false
|
|
}
|
|
|
|
for i := range ids {
|
|
if "S-1-5-32-544" == ids[i] {
|
|
return true
|
|
}
|
|
}
|
|
|
|
return false
|
|
}
|