diff --git a/dist/ae-send_windows_amd64.exe b/dist/ae-send_windows_amd64.exe index ae16537..2b9c877 100755 Binary files a/dist/ae-send_windows_amd64.exe and b/dist/ae-send_windows_amd64.exe differ diff --git a/main.go b/main.go index 3d06a3b..8c48f42 100644 --- a/main.go +++ b/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 +}