I'm writing a (Win32 Console) program that wraps another process; it takes parameters as in the following example:
runas.exe user notepad foo.txt
That is: runas
parses user
and then will run notepad, passing the remaining parameters.
My problem is that argv
is broken down into individual parameters, but CreateProcessAsUser
requires a single lpszCommandLine
parameter.
Building this command line is probably not as simple as just joining argv
back together with spaces. Any pointers?
This is just an example. My first argument isn't actually a user name, and might have spaces in it. This makes manually parsing the result of GetCommandLine
tricky.
Similarly, a naive concatenation of argv
won't work, because it needs to deal with the case where the original arguments were quoted and might have spaces in them.