From 64106a4a77d7b29940f82d57ff038f58d9e9d51b Mon Sep 17 00:00:00 2001 From: dido18 Date: Mon, 15 Dec 2025 14:18:29 +0100 Subject: [PATCH 1/3] Add WindowVisibility option to RunElevated on Windows --- runas_windows.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/runas_windows.go b/runas_windows.go index 418f530..8ea520d 100644 --- a/runas_windows.go +++ b/runas_windows.go @@ -123,9 +123,16 @@ func shellExecuteError(code windows.Handle) error { } } +type WindowVisibility int + +const ( + WindowHidden WindowVisibility = iota + WindowShown +) + // RunElevated starts the given process with elevated priviledges. // An UAC prompt is displayed to the user to confirm the action. -func RunElevated(executable, workingDir string, args []string, awaitProcCompletion bool) (int, error) { +func RunElevated(executable, workingDir string, args []string, awaitProcCompletion bool, visibility WindowVisibility) (int, error) { var verb, file, directory, parameters *uint16 var err error @@ -142,13 +149,23 @@ func RunElevated(executable, workingDir string, args []string, awaitProcCompleti return 0, err } + var showMode int32 + switch visibility { + case WindowHidden: + showMode = windows.SW_SHOW + case WindowShown: + showMode = windows.SW_HIDE + default: + return 0, fmt.Errorf("invalid visibility mode: %d", visibility) + } + execInfo := &shellExecuteInfo{ size: uint32(unsafe.Sizeof(shellExecuteInfo{})), verb: verb, directory: directory, file: file, parameters: parameters, - show: windows.SW_HIDE, + show: showMode, mask: SEE_MASK_NOCLOSEPROCESS, } if !shellExecuteEx(execInfo) { From 7d00b16f1db7e9a70592af1996913b9f9866d746 Mon Sep 17 00:00:00 2001 From: dido18 Date: Mon, 15 Dec 2025 14:40:57 +0100 Subject: [PATCH 2/3] Replace WindowVisibility with showWindow bool in RunElevated --- runas_windows.go | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/runas_windows.go b/runas_windows.go index 8ea520d..fc9d37c 100644 --- a/runas_windows.go +++ b/runas_windows.go @@ -123,16 +123,9 @@ func shellExecuteError(code windows.Handle) error { } } -type WindowVisibility int - -const ( - WindowHidden WindowVisibility = iota - WindowShown -) - // RunElevated starts the given process with elevated priviledges. // An UAC prompt is displayed to the user to confirm the action. -func RunElevated(executable, workingDir string, args []string, awaitProcCompletion bool, visibility WindowVisibility) (int, error) { +func RunElevated(executable, workingDir string, args []string, awaitProcCompletion bool, showWindow bool) (int, error) { var verb, file, directory, parameters *uint16 var err error @@ -149,14 +142,9 @@ func RunElevated(executable, workingDir string, args []string, awaitProcCompleti return 0, err } - var showMode int32 - switch visibility { - case WindowHidden: + var showMode int32 = windows.SW_HIDE + if showWindow { showMode = windows.SW_SHOW - case WindowShown: - showMode = windows.SW_HIDE - default: - return 0, fmt.Errorf("invalid visibility mode: %d", visibility) } execInfo := &shellExecuteInfo{ From ceb6b92a883e20a5895890715bd4b706a72d0a7b Mon Sep 17 00:00:00 2001 From: dido18 Date: Mon, 15 Dec 2025 14:53:19 +0100 Subject: [PATCH 3/3] Rename showWindow to hideWindow in RunElevated function --- runas_windows.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/runas_windows.go b/runas_windows.go index fc9d37c..ff25888 100644 --- a/runas_windows.go +++ b/runas_windows.go @@ -125,7 +125,7 @@ func shellExecuteError(code windows.Handle) error { // RunElevated starts the given process with elevated priviledges. // An UAC prompt is displayed to the user to confirm the action. -func RunElevated(executable, workingDir string, args []string, awaitProcCompletion bool, showWindow bool) (int, error) { +func RunElevated(executable, workingDir string, args []string, awaitProcCompletion bool, hideWindow bool) (int, error) { var verb, file, directory, parameters *uint16 var err error @@ -142,9 +142,9 @@ func RunElevated(executable, workingDir string, args []string, awaitProcCompleti return 0, err } - var showMode int32 = windows.SW_HIDE - if showWindow { - showMode = windows.SW_SHOW + var showMode int32 = windows.SW_SHOW + if hideWindow { + showMode = windows.SW_HIDE } execInfo := &shellExecuteInfo{