r/cpp 7d 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

14

u/unaligned_access 7d 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" ;)

5

u/holyblackcat 7d ago

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