<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Why does the CreateProcess function modify its input command line?</title><link>http://blogs.msdn.com/oldnewthing/archive/2009/06/01/9673254.aspx</link><description>Somebody was trying too hard to be clever.</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Why does the CreateProcess function modify its input command line?</title><link>http://blogs.msdn.com/oldnewthing/archive/2009/06/01/9673254.aspx#9678113</link><pubDate>Mon, 01 Jun 2009 17:11:05 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9678113</guid><dc:creator>jMarkP</dc:creator><description>&lt;p&gt;My psychic Microsoft compatibility hack sense is tingling and I'm guessing the answer has something to do with a program which relies on the Unicode function modifying its parameter somehow.&lt;/p&gt;
&lt;p&gt;Am I warm?&lt;/p&gt;
</description></item><item><title>re: Why does the CreateProcess function modify its input command line?</title><link>http://blogs.msdn.com/oldnewthing/archive/2009/06/01/9673254.aspx#9678136</link><pubDate>Mon, 01 Jun 2009 17:20:09 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9678136</guid><dc:creator>Rob Manderson</dc:creator><description>&lt;p&gt;I'd guess the ANSI version can do a string allocate for two reasons:&lt;/p&gt;
&lt;p&gt;1 - It's a wrapper - the allocation is done 'before' calling into the real CreateProcess.&lt;/p&gt;
&lt;p&gt;2 - The debugger will be launching the Unicode version directly.&lt;/p&gt;
</description></item><item><title>re: Why does the CreateProcess function modify its input command line?</title><link>http://blogs.msdn.com/oldnewthing/archive/2009/06/01/9673254.aspx#9678174</link><pubDate>Mon, 01 Jun 2009 17:32:26 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9678174</guid><dc:creator>Jack Mathews</dc:creator><description>&lt;p&gt;Since the ANSI version is essentially a shim utility library on top of the UNICODE kernel, a crash in ANSI functions will not cause the recursive crash you talk about. &lt;/p&gt;
</description></item><item><title>re: Why does the CreateProcess function modify its input command line?</title><link>http://blogs.msdn.com/oldnewthing/archive/2009/06/01/9673254.aspx#9678247</link><pubDate>Mon, 01 Jun 2009 17:58:28 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9678247</guid><dc:creator>Mark</dc:creator><description>&lt;p&gt;It looks like CreateProcessW does allocate from Peb-&amp;gt;ProcessHeap to sort out the path. &amp;nbsp;Not sure how long this has been the case, though.&lt;/p&gt;
</description></item><item><title>re: Why does the CreateProcess function modify its input command line?</title><link>http://blogs.msdn.com/oldnewthing/archive/2009/06/01/9673254.aspx#9678387</link><pubDate>Mon, 01 Jun 2009 19:00:52 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9678387</guid><dc:creator>Alexandre Grigoriev</dc:creator><description>&lt;p&gt;I'll chime in. &lt;/p&gt;
&lt;p&gt;First, CreateProcessA doesn't need a mutable string, because it will first be converted to an UNICODE string and then passed to CreateProcessW.&lt;/p&gt;
&lt;p&gt;Second, you could allocate temporary storage on stack (using _alloca), or use VirtualAlloc which doesn't depend on any usermode locks.&lt;/p&gt;
&lt;p&gt;Third, the whole idea of running JIT launcher in a context of a failed process is flawed. At least, I hope it's done in context of a dedicated thread (in which case you've got a meg of stack reserved, too, and can use _alloca).&lt;/p&gt;
</description></item><item><title>re: Why does the CreateProcess function modify its input command line?</title><link>http://blogs.msdn.com/oldnewthing/archive/2009/06/01/9673254.aspx#9679268</link><pubDate>Mon, 01 Jun 2009 20:57:02 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9679268</guid><dc:creator>W</dc:creator><description>&lt;p&gt;Would a 64kB allocation on stack break something?&lt;/p&gt;
</description></item><item><title>re: Why does the CreateProcess function modify its input command line?</title><link>http://blogs.msdn.com/oldnewthing/archive/2009/06/01/9673254.aspx#9681018</link><pubDate>Mon, 01 Jun 2009 22:39:01 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9681018</guid><dc:creator>Nick</dc:creator><description>&lt;p&gt;Simple, really. &amp;nbsp;Nobody uses Unicode so there's no reason to spend time fixing it!&lt;/p&gt;
&lt;p&gt;I kid, I kid (well, kinda :)...&lt;/p&gt;
</description></item><item><title>re: Why does the CreateProcess function modify its input command line?</title><link>http://blogs.msdn.com/oldnewthing/archive/2009/06/01/9673254.aspx#9681403</link><pubDate>Mon, 01 Jun 2009 22:57:31 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9681403</guid><dc:creator>waleri</dc:creator><description>&lt;p&gt;I suspect the length of the argument of CreateProcessA may not exceed MAX_PATH.&lt;/p&gt;
</description></item><item><title>re: Why does the CreateProcess function modify its input command line?</title><link>http://blogs.msdn.com/oldnewthing/archive/2009/06/01/9673254.aspx#9681679</link><pubDate>Mon, 01 Jun 2009 23:10:40 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9681679</guid><dc:creator>waleri</dc:creator><description>&lt;P&gt;While we're at it, what is the reason *not* to fix the contract for CreateProcess? Even if argument is changed from LPTSTR to LPCTSTR this should be backward compatible. Unless of course CreateProcess *still* modifies that memory...&lt;/P&gt;
&lt;DIV class=post&gt;[&lt;I&gt;Changing the function prototype breaks existing source code. Try it: &lt;PRE&gt;typedef BOOL (WINAPI *CREATEPROCESSFN)(
 LPCTSTR lpApplicationName,
 LPTSTR lpCommandLine,
 LPSECURITY_ATTRIBUTES lpProcessAttributes,
 LPSECURITY_ATTRIBUTES lpThreadAttributes,
 BOOL bInheritHandles,
 DWORD dwCreationFlags,
 LPVOID lpEnvironment,
 LPCTSTR lpCurrentDirectory,
 LPSTARTUPINFO lpStartupInfo,
 LPPROCESS_INFORMATION lpProcessInformation);

CREATEPROCESSFN DoCreateProcess = MyCreateProcess;

typedef BOOL WINAPI MyCreateProcess(
 LPCTSTR lpApplicationName,
 LPTSTR lpCommandLine,
 LPSECURITY_ATTRIBUTES lpProcessAttributes,
 LPSECURITY_ATTRIBUTES lpThreadAttributes,
 BOOL bInheritHandles,
 DWORD dwCreationFlags,
 LPVOID lpEnvironment,
 LPCTSTR lpCurrentDirectory,
 LPSTARTUPINFO lpStartupInfo,
 LPPROCESS_INFORMATION lpProcessInformation)
{
 if (!RedirectCreateProcess) {
  // disable trappingin in future callers
  DoCreateProcess = CreateProcess;
  return CreateProcess(...);
 }
 ...
}
&lt;/PRE&gt;I learned this lesson the hard way. -Raymond&lt;/I&gt;]&lt;/DIV&gt;</description></item><item><title>re: Why does the CreateProcess function modify its input command line?</title><link>http://blogs.msdn.com/oldnewthing/archive/2009/06/01/9673254.aspx#9682179</link><pubDate>Mon, 01 Jun 2009 23:56:14 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9682179</guid><dc:creator>Gabe</dc:creator><description>&lt;p&gt;Is there any reason CreateProcessW couldn't trap the write-fail exception and only then allocate memory? That would solve the problem of attempting to call it with a string from a page marked PAGE_READONLY, so at least you don't get arbitrary failures.&lt;/p&gt;
</description></item><item><title>re: Why does the CreateProcess function modify its input command line?</title><link>http://blogs.msdn.com/oldnewthing/archive/2009/06/01/9673254.aspx#9682852</link><pubDate>Tue, 02 Jun 2009 03:19:52 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9682852</guid><dc:creator>MadQ</dc:creator><description>&lt;p&gt;Some programs also play around with the input command line. verclsid.exe seems to do this. &lt;/p&gt;
</description></item><item><title>re: Why does the CreateProcess function modify its input command line?</title><link>http://blogs.msdn.com/oldnewthing/archive/2009/06/01/9673254.aspx#9683014</link><pubDate>Tue, 02 Jun 2009 03:56:43 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9683014</guid><dc:creator>NickPick</dc:creator><description>&lt;p&gt;Exercise: &lt;/p&gt;
&lt;p&gt;Explain why a design decision of CreateProcess function was probably not done by &amp;quot;somebody back in the 1980s&amp;quot;&lt;/p&gt;
</description></item><item><title>re: Why does the CreateProcess function modify its input command line?</title><link>http://blogs.msdn.com/oldnewthing/archive/2009/06/01/9673254.aspx#9683487</link><pubDate>Tue, 02 Jun 2009 07:31:43 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9683487</guid><dc:creator>waleri</dc:creator><description>&lt;p&gt;&amp;gt;&amp;gt;&amp;gt; Some programs also play around with the input command line. verclsid.exe seems to do this.&lt;/p&gt;
&lt;p&gt;Isn't command line is a copy? After all, the child process should access it in its own address space.&lt;/p&gt;
</description></item><item><title>re: Why does the CreateProcess function modify its input command line?</title><link>http://blogs.msdn.com/oldnewthing/archive/2009/06/01/9673254.aspx#9685359</link><pubDate>Tue, 02 Jun 2009 16:22:22 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9685359</guid><dc:creator>dave</dc:creator><description>&lt;p&gt;&amp;gt;Is there any reason CreateProcessW couldn't&lt;/p&gt;
&lt;p&gt;&amp;gt;trap the write-fail exception and only then&lt;/p&gt;
&lt;p&gt;&amp;gt;allocate memory? That would solve the problem &lt;/p&gt;
&lt;p&gt;&amp;gt;of attempting to call it with a string from &lt;/p&gt;
&lt;p&gt;&amp;gt;page marked PAGE_READONLY, so at least you &lt;/p&gt;
&lt;p&gt;&amp;gt;don't get arbitrary failures.&lt;/p&gt;
&lt;p&gt;Well, I'd say that no-one gets arbitrary failures today, anyway. &amp;nbsp;People who fail to read the documentation get exactly the failures that the documentation implied they'd get. 'Unexpected by programmer X' != 'arbitrary'.&lt;/p&gt;
&lt;p&gt;And in any case, why futz around with an API that has managed to work adequately well for the past 16 years? &amp;nbsp;Sure, it's a little odd the first time you bump into it, but aren't there better things to work on?&lt;/p&gt;
&lt;p&gt;But if we are going to futz with CreateProcess, can we remove the mess that allows you to specify the image name EITHER through a separate parameter or as part of the command line? &lt;/p&gt;
&lt;p&gt;(Joking... it's way too late for that).&lt;/p&gt;
</description></item><item><title>re: Why does the CreateProcess function modify its input command line?</title><link>http://blogs.msdn.com/oldnewthing/archive/2009/06/01/9673254.aspx#9686890</link><pubDate>Wed, 03 Jun 2009 00:17:50 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9686890</guid><dc:creator>peterchen</dc:creator><description>&lt;p&gt;@Gabe - that would be worse: a function that promises not to modify memory, but does. (And if it doesn't make that promise, there's no point in fixing it).&lt;/p&gt;
&lt;p&gt;waleri - interesting thought! MSDN doesn't say anything about a limit, though.&lt;/p&gt;
&lt;p&gt;Now, gotta chew through that sample...&lt;/p&gt;
</description></item><item><title>re: Why does the CreateProcess function modify its input command line?</title><link>http://blogs.msdn.com/oldnewthing/archive/2009/06/01/9673254.aspx#9688967</link><pubDate>Wed, 03 Jun 2009 06:12:46 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9688967</guid><dc:creator>Brad</dc:creator><description>&lt;p&gt;Since people seem to have danced around the answer, is it:&lt;/p&gt;
&lt;p&gt;The JIT debugger is always launched with CreateProcessW? (so that case can never allocate from the heap).&lt;/p&gt;
</description></item><item><title>re: Why does the CreateProcess function modify its input command line?</title><link>http://blogs.msdn.com/oldnewthing/archive/2009/06/01/9673254.aspx#9689699</link><pubDate>Wed, 03 Jun 2009 09:27:09 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9689699</guid><dc:creator>Alexey Borzenkov</dc:creator><description>&lt;p&gt;&amp;gt; Why is it okay for the ANSI version of the CreateProcess to allocate a temporary string&lt;/p&gt;
&lt;p&gt;I'm not 100% sure, but from what I seen during numerous debugging sessions I think that all path related ANSI functions use the same thread-local buffer, so it is either already preallocated, or is not allocated at all.&lt;/p&gt;
</description></item><item><title>re: you don't want to allocate memory on the heap</title><link>http://blogs.msdn.com/oldnewthing/archive/2009/06/01/9673254.aspx#9690224</link><pubDate>Wed, 03 Jun 2009 11:24:14 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9690224</guid><dc:creator>Someone</dc:creator><description>&lt;P&gt;"When a program crashes, the just in time debugger is launched with the CreateProcess function, and you don't want to allocate memory on the heap if the reason the program crashed is that the heap is corrupted."&lt;/P&gt;
&lt;P&gt;I do not follow that argument. It would only make sense if that command line memory were the only allocation done by CreateProcess. If so, where would CreateProcess get the process stack or the memory for the debugger image from?&lt;/P&gt;
&lt;P&gt;Or is that debugger running in some zombie state all the time, and was CreateProcess hacked to not really launch it, but revive it from the dead? If so, why would one add that code to CreateProcess, rather than creating a new function "StartJITDebugger"?&lt;/P&gt;
&lt;DIV class=post&gt;[&lt;I&gt;Um, the debugger is a separate process. Heap corruption is process-local. -Raymond&lt;/I&gt;]&lt;/DIV&gt;</description></item><item><title>re: Why does the CreateProcess function modify its input command line?</title><link>http://blogs.msdn.com/oldnewthing/archive/2009/06/01/9673254.aspx#9691253</link><pubDate>Wed, 03 Jun 2009 16:45:59 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9691253</guid><dc:creator>Mike Dimmick</dc:creator><description>&lt;p&gt;@Someone: when dealing with CreateProcess, you really have to think in terms of the calling, parent, process, and the child process it creates.&lt;/p&gt;
&lt;p&gt;The article is talking about a buffer that CreateProcess is (not) creating in the context of the calling process. The process's initial thread stack is not directly created by CreateProcess but by the process startup code in the kernel, in the context of the new process. The virtual memory for the program code is a shared-memory section backed by the program image file, which is paged in on demand.&lt;/p&gt;
&lt;p&gt;I'm surprised that Kernel32's default unhandled-exception code is creating the debugger process directly. I would have thought it would instead send a message to the Win32 subsystem to invoke a debugger on its behalf.&lt;/p&gt;
&lt;p&gt;A debugger is just a standard Win32 program which calls DebugActiveProcess to debug another process, or creates a process with one of the DEBUG_PROCESS or DEBUG_ONLY_THIS_PROCESS flags. The debugger then calls WaitForDebugEvent to have Windows tell it about new threads, loaded or unloaded DLLs, debugging messages, thread exits, and exceptions. Breakpoints are set by modifying the code of the target process (with WriteProcessMemory) to place a breakpoint instruction at that location instead; that instruction causes an exception (code STATUS_BREAKPOINT, 0x80000003) to occur in the program, which is reported through WaitForDebugEvent.&lt;/p&gt;
&lt;p&gt;To restart, the debugger replaces the breakpoint with the code that should have been at that location, sets the thread's processor context to single-step (execute one instruction), then restarts with ContinueDebugEvent. A STATUS_SINGLE_STEP exception is then raised in the program, the debugger rewrites the breakpoint, and again continues execution to continue at full speed.&lt;/p&gt;
</description></item><item><title>re: Why does the CreateProcess function modify its input command line?</title><link>http://blogs.msdn.com/oldnewthing/archive/2009/06/01/9673254.aspx#9694343</link><pubDate>Thu, 04 Jun 2009 02:08:10 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9694343</guid><dc:creator>Jamie Anderson</dc:creator><description>&lt;P&gt;I would hazard a guess that the ANSI wrapper functions in the kernel have their own private heap that they use to allocate memory. That would avoid the matter because any memory allocation will happen on a different heap to the one that's been corrupted.&lt;/P&gt;
&lt;DIV class=post&gt;[&lt;I&gt;What if the private heap is corrupted? -Raymond&lt;/I&gt;]&lt;/DIV&gt;</description></item><item><title>Почему функция CreateProcess изменяет переданную на вход командную строку?</title><link>http://blogs.msdn.com/oldnewthing/archive/2009/06/01/9673254.aspx#9698722</link><pubDate>Thu, 04 Jun 2009 10:49:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9698722</guid><dc:creator>Блог Рэймонда Чена (перевод)</dc:creator><description>&lt;p&gt;Одна из неприятных особенностей функции CreateProcess состоит в том, что параметр lpCommandLine должен&lt;/p&gt;
</description></item><item><title>Why CreateProcess commandline parameter should not be read-only memory? &amp;laquo; Sharing my thoughts&amp;#8230;</title><link>http://blogs.msdn.com/oldnewthing/archive/2009/06/01/9673254.aspx#9700112</link><pubDate>Thu, 04 Jun 2009 22:09:26 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9700112</guid><dc:creator>Why CreateProcess commandline parameter should not be read-only memory? &amp;laquo; Sharing my thoughts&amp;#8230;</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://sarathc.wordpress.com/2009/06/05/why-createprocess-commandline-parameter-should-not-be-read-only-memory/"&gt;http://sarathc.wordpress.com/2009/06/05/why-createprocess-commandline-parameter-should-not-be-read-only-memory/&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>re: Why does the CreateProcess function modify its input command line?</title><link>http://blogs.msdn.com/oldnewthing/archive/2009/06/01/9673254.aspx#9700330</link><pubDate>Fri, 05 Jun 2009 00:42:58 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9700330</guid><dc:creator>Someone</dc:creator><description>&lt;p&gt;@Mike Dimmick: thanks for the explanation. I knew most of what you said, except for what surprised you, too: that, apparently, the 'crashed' program launches the debugger (or, probably more precisely: the kernel calls CreateProcess to start the debugger while in the context of the crashed application). But even with that, I do not see why one would have to modify the string you pass as the lpCommandLine to figure out where the program name ends and the command line arguments begin.&lt;/p&gt;
&lt;p&gt;The first thing I can think of is that it is not the figuring out, but the use of the program name as an argument to some other system call (FindFile?) that requires the modification. I guess the change would be to overwrite a space in the command line with a NULL. I have seen people do the reverse on Unix systems: creating a program's command line by replacing the NULLs at the end of all but the last of the argv entries by a space. I doubt that that is guaranteed to work, but it did on the one system where I saw somebody do that.&lt;/p&gt;
&lt;p&gt;A second possibility could be that CreateProcess does some Unicode normalization in-place. That would also explain why the the ANSI version never modifies that argument.&lt;/p&gt;
</description></item><item><title>re: Why does the CreateProcess function modify its input command line?</title><link>http://blogs.msdn.com/oldnewthing/archive/2009/06/01/9673254.aspx#9700581</link><pubDate>Fri, 05 Jun 2009 04:32:02 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9700581</guid><dc:creator>GregM</dc:creator><description>&lt;p&gt;&amp;quot;I guess the change would be to overwrite a space in the command line with a NULL.&amp;quot;&lt;/p&gt;
&lt;p&gt;Yes, that's what the documentation for CreateProcess says.&lt;/p&gt;
</description></item><item><title>re: Why does the CreateProcess function modify its input command line?</title><link>http://blogs.msdn.com/oldnewthing/archive/2009/06/01/9673254.aspx#9701807</link><pubDate>Fri, 05 Jun 2009 22:04:44 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9701807</guid><dc:creator>Random832</dc:creator><description>&lt;p&gt;Wait... what if there is no space between the program name and arguments - like &amp;quot;cmd/?&amp;quot; (or any /flags generally) - where does it put the null then?&lt;/p&gt;
</description></item><item><title>re: Why does the CreateProcess function modify its input command line?</title><link>http://blogs.msdn.com/oldnewthing/archive/2009/06/01/9673254.aspx#9702692</link><pubDate>Sat, 06 Jun 2009 13:01:47 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9702692</guid><dc:creator>Falcon</dc:creator><description>&lt;p&gt;@Random832: Try typing &amp;quot;cmd/?&amp;quot; into the Run dialog text box and see what happens!&lt;/p&gt;
&lt;p&gt;(Tested on Windows XP, can't speak for Vista or any other versions...)&lt;/p&gt;
</description></item><item><title>re: Why does the CreateProcess function modify its input command line?</title><link>http://blogs.msdn.com/oldnewthing/archive/2009/06/01/9673254.aspx#9707959</link><pubDate>Mon, 08 Jun 2009 15:00:36 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9707959</guid><dc:creator>teo</dc:creator><description>&lt;p&gt;While CreateProcess is peculiar, the real fun is in ShellExecuteEx. Yesterday, I had to code a self-elevating program. Basicaly it boilds down to: &lt;/p&gt;
&lt;p&gt;if(!IsUserAnAdmin())&lt;/p&gt;
&lt;p&gt; &amp;nbsp;ShellExecute(&amp;quot;runas&amp;quot;, my-own-command-line)&lt;/p&gt;
&lt;p&gt;Well, doh! It turns out that Windows (whose mantra used to be &amp;quot;Easy stuff should be easy and hard stuff should be possible&amp;quot;) considers this the hard stuff... &lt;/p&gt;
&lt;p&gt;My first try:&lt;/p&gt;
&lt;p&gt;ShellExecute(0, L&amp;quot;runas&amp;quot;, argv[0], GetCommandLine() ... ), nope it won't budge&lt;/p&gt;
&lt;p&gt;2nd try:&lt;/p&gt;
&lt;p&gt;ShellExecute(0, L&amp;quot;runas&amp;quot;, 0, GetCommandLine() ...)&lt;/p&gt;
&lt;p&gt;And so on and so forth. At the end I had to write a helper function which goes through the command line of the current process, builds a specially escaped, massaged, tangerine-flavoured, painted-white-and-pink ... command line which after digested by the ShellExecute monstrosity will produce the one I started with. Btw, whoever designed the whole &amp;quot;runas&amp;quot; hack obviously decided that console applications are so out-of-fashion. What window handle a console app is supposed to feed it?&lt;/p&gt;
&lt;p&gt;But that is just a minor hack, i fixed it in less than 15 mins. If you want to have a taste of Hell, go compile a program which should run on XP with Vista/2k8 Platform SDK and imports CreateVssBackupComponents() function. Now that is one fine mess. Where to start? The wrong documentation? The fact that on XP it's exported as extern &amp;quot;C++&amp;quot;, which makes it exported with C++ mangled name, which obviously differs between 32 and 64 bit compilers and is not natively consumable by any other language in existence, being it another c++ compiler, delphi or what not? The most sickening part is the &amp;quot;fix&amp;quot; - in the form of an INLINE FUNCTION in the platform sdk headers; making it completely impossible to compile a program targeting XP using the official function name ... Microsoft, Microsoft, what have I done to bring thy wrath upon me?&lt;/p&gt;
</description></item></channel></rss>