This commit is contained in:
Colin 2024-06-26 10:52:16 -04:00
parent 432cd821eb
commit 96a350bb7d
2 changed files with 22 additions and 0 deletions

Binary file not shown.

22
main.go
View File

@ -3,6 +3,8 @@ package main
import ( import (
"log" "log"
"os" "os"
"os/exec"
"strings"
"golang.org/x/sys/windows/registry" "golang.org/x/sys/windows/registry"
) )
@ -13,6 +15,7 @@ func main() {
case "install": case "install":
installContextMenuItem() installContextMenuItem()
case "uninstall": case "uninstall":
ensureAdminPrivileges()
uninstallContextMenuItem() uninstallContextMenuItem()
default: default:
processFile(os.Args[1]) processFile(os.Args[1])
@ -70,3 +73,22 @@ func uninstallContextMenuItem() {
log.Println("Context menu item removed successfully.") 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
}