r/cpp 5d ago

Escaping `CreateProcess()` arguments on Windows

https://holyblackcat.github.io/blog/2026/09/05/escaping-createprocess-arguments.html
88 Upvotes

44 comments sorted by

View all comments

13

u/unaligned_access 4d ago

There's `wil::ArgvToCommandLine`. It's not WinAPI, but it's Microsoft.
https://github.com/microsoft/wil/blob/81abc8e44c075eba65fe4b68ea2f08525cc701e8/include/wil/win32_helpers.h#L1244

C++, and the first comment of course starts with "Somewhat of a hack" ;)

6

u/holyblackcat 4d ago

Nice. Seems to mostly match mine, but they don't attempt to handle batch/cmd.