Skip to content

Commit 00acb42

Browse files
author
Johan Knutzen
committed
syscall: expose bInheritHandles of CreateProcess
Certain use cases require this parameter to be false. This includes spawning a child process in a different windows session than session 0. Docs regarding the behavior of this parameter to CreateProcess: https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessa
1 parent 58e51b1 commit 00acb42

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/syscall/exec_windows.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,13 @@ type ProcAttr struct {
235235
}
236236

237237
type SysProcAttr struct {
238-
HideWindow bool
239-
CmdLine string // used if non-empty, else the windows command line is built by escaping the arguments passed to StartProcess
240-
CreationFlags uint32
241-
Token Token // if set, runs new process in the security context represented by the token
242-
ProcessAttributes *SecurityAttributes // if set, applies these security attributes as the descriptor for the new process
243-
ThreadAttributes *SecurityAttributes // if set, applies these security attributes as the descriptor for the main thread of the new process
238+
HideWindow bool
239+
CmdLine string // used if non-empty, else the windows command line is built by escaping the arguments passed to StartProcess
240+
CreationFlags uint32
241+
Token Token // if set, runs new process in the security context represented by the token
242+
ProcessAttributes *SecurityAttributes // if set, applies these security attributes as the descriptor for the new process
243+
ThreadAttributes *SecurityAttributes // if set, applies these security attributes as the descriptor for the main thread of the new process
244+
DontInheritHandles bool
244245
}
245246

246247
var zeroProcAttr ProcAttr
@@ -341,9 +342,9 @@ func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid int, handle
341342

342343
flags := sys.CreationFlags | CREATE_UNICODE_ENVIRONMENT
343344
if sys.Token != 0 {
344-
err = CreateProcessAsUser(sys.Token, argv0p, argvp, sys.ProcessAttributes, sys.ThreadAttributes, true, flags, createEnvBlock(attr.Env), dirp, si, pi)
345+
err = CreateProcessAsUser(sys.Token, argv0p, argvp, sys.ProcessAttributes, sys.ThreadAttributes, !sys.DontInheritHandles, flags, createEnvBlock(attr.Env), dirp, si, pi)
345346
} else {
346-
err = CreateProcess(argv0p, argvp, sys.ProcessAttributes, sys.ThreadAttributes, true, flags, createEnvBlock(attr.Env), dirp, si, pi)
347+
err = CreateProcess(argv0p, argvp, sys.ProcessAttributes, sys.ThreadAttributes, !sys.DontInheritHandles, flags, createEnvBlock(attr.Env), dirp, si, pi)
347348
}
348349
if err != nil {
349350
return 0, 0, err

0 commit comments

Comments
 (0)