win32 API
Create Processes
-
CreateProcessW
File Association
-
Use
ShellExecuteExorShellExecuteW, to open files by association (e.g.,foo.pdfwith Acrobat). -
CreateProcessdoes not handle file associations.
UAC Elevation
-
CreateProcessWruns with the callerβs token. It will not trigger UAC elevation. -
To elevate use
ShellExecuteExwithrunasor useCreateProcessWithTokenW/CreateProcessAsUserwith the right token.
"Conveniences" you lose by not using a shell
-
Built-ins :
-
Will not run
dir,cd, or othercmd.exebuilt-ins. Those are implemented inside the shell.
-
-
.bat / .ps1 files :
-
*.bat,*.cmd,.ps1are not native executables. -
*.batmust be run by cmd.execmd.exe /c yourscript.bat(or use the shell). -
*.ps1must be run by PowerShell (or invoked viapwsh -File).
-
-
Pipes :
-
This refers to the usage of something like:
-
>-
cmd.exe: Redirect stdout to a file (overwrite).
-
powershell: Redirect stdout to a file (overwrite).
-
-
|-
cmd.exe: byte-stream pipe.
-
powershell: object pipeline.
-
-
-
You must create pipes yourself and wire
STARTUPINFO.hStdInput/hStdOutputandbInheritHandles. -
You control the environment block and current directory. If you want inherited handles or specific stdio redirection you must set those in
STARTUPINFOand usebInheritHandles. -
Odin does this with the
win32api by:
&win32.STARTUPINFOW{ cb = size_of(win32.STARTUPINFOW), hStdError Β = stderr_handle, hStdOutput = stdout_handle, hStdInput Β = stdin_handle, dwFlags = win32.STARTF_USESTDHANDLES, }, -
-
Conditionals :
-
This refers to the usage of something like:
-
||-
cmd.exe: run RHS if LHS fails.
-
powershell: run RHS if LHS fails.
-
-
&&-
cmd.exe: run RHS if LHS success.
-
powershell: run RHS if LHS success.
-
-
-
Parent or shell must implement conditional logic. Parent must check exit code and decide.
-
-
Sequence invoke :
-
This refers to the usage of something like:
-
&-
cmd.exe: Command operator. Runs next command unconditionally.
-
-
;-
powershell: Command operator.
-
-
-
If you want sequencing invoke multiple
CreateProcessWcalls or implement sequencing logic in your program.
-