Fixup
This commit is contained in:
parent
432cd821eb
commit
96a350bb7d
Binary file not shown.
22
main.go
22
main.go
|
@ -3,6 +3,8 @@ package main
|
|||
import (
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/sys/windows/registry"
|
||||
)
|
||||
|
@ -13,6 +15,7 @@ func main() {
|
|||
case "install":
|
||||
installContextMenuItem()
|
||||
case "uninstall":
|
||||
ensureAdminPrivileges()
|
||||
uninstallContextMenuItem()
|
||||
default:
|
||||
processFile(os.Args[1])
|
||||
|
@ -70,3 +73,22 @@ func uninstallContextMenuItem() {
|
|||
log.Println("Context menu item removed successfully.")
|
||||
}
|
||||
}
|
||||
|
||||
func ensureAdminPrivileges() {
|
||||
if !isAdmin() {
|
||||
// Relaunch the application with elevated privileges
|
||||
exePath, _ := os.Executable()
|
||||
args := strings.Join(os.Args, " ")
|
||||
cmd := exec.Command("runas", "/user:Administrator", exePath+" "+args)
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to relaunch as admin: %v", err)
|
||||
}
|
||||
os.Exit(0)
|
||||
}
|
||||
}
|
||||
|
||||
func isAdmin() bool {
|
||||
_, err := os.Open("\\\\.\\PHYSICALDRIVE0")
|
||||
return err == nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue