update v-advance
This commit is contained in:
12
internal/utils/perm_linux.go
Normal file
12
internal/utils/perm_linux.go
Normal file
@@ -0,0 +1,12 @@
|
||||
//go:build linux
|
||||
|
||||
package utils
|
||||
|
||||
import "os"
|
||||
|
||||
// IsAdmin 检测当前用户是否为 root(UID=0)
|
||||
func IsAdmin() bool {
|
||||
return os.Geteuid() == 0
|
||||
}
|
||||
|
||||
|
||||
20
internal/utils/perm_windows.go
Normal file
20
internal/utils/perm_windows.go
Normal file
@@ -0,0 +1,20 @@
|
||||
//go:build windows
|
||||
|
||||
package utils
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
// IsAdmin 检测当前用户是否为管理员。
|
||||
// 通过执行 `net session` 命令判断:该命令只有在管理员权限下才会成功。
|
||||
func IsAdmin() bool {
|
||||
cmd := exec.Command("net", "session")
|
||||
// 不关心输出,只关心能否成功执行
|
||||
if err := cmd.Run(); err != nil {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user