Skip to content

Commit 89d4510

Browse files
authored
feat: Add hideWindow option to RunElevated on Windows (#7)
* Add WindowVisibility option to RunElevated on Windows * Replace WindowVisibility with showWindow bool in RunElevated * Rename showWindow to hideWindow in RunElevated function
1 parent 99ed364 commit 89d4510

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

runas_windows.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func shellExecuteError(code windows.Handle) error {
125125

126126
// RunElevated starts the given process with elevated priviledges.
127127
// An UAC prompt is displayed to the user to confirm the action.
128-
func RunElevated(executable, workingDir string, args []string, awaitProcCompletion bool) (int, error) {
128+
func RunElevated(executable, workingDir string, args []string, awaitProcCompletion bool, hideWindow bool) (int, error) {
129129
var verb, file, directory, parameters *uint16
130130
var err error
131131

@@ -142,13 +142,18 @@ func RunElevated(executable, workingDir string, args []string, awaitProcCompleti
142142
return 0, err
143143
}
144144

145+
var showMode int32 = windows.SW_SHOW
146+
if hideWindow {
147+
showMode = windows.SW_HIDE
148+
}
149+
145150
execInfo := &shellExecuteInfo{
146151
size: uint32(unsafe.Sizeof(shellExecuteInfo{})),
147152
verb: verb,
148153
directory: directory,
149154
file: file,
150155
parameters: parameters,
151-
show: windows.SW_HIDE,
156+
show: showMode,
152157
mask: SEE_MASK_NOCLOSEPROCESS,
153158
}
154159
if !shellExecuteEx(execInfo) {

0 commit comments

Comments
 (0)