I have a program that attempts to restart Explorer in Windows 7; it first ends the process, then starts it again.
Simple?
So it looks -- it indeed seems to work. However, I noticed something funny: When I try to start a program (say, XP's Power Calculator powertoy) under compatibility mode, it no longer works! Nothing happens -- the process is created and immediately quits.
If I run Explorer through the Run dialog of Task Manager, the program runs fine.
What's going on?!
#include <windows.h>
int main()
{
PROCESS_INFORMATION pi;
STARTUPINFO si = {sizeof(si)};
TCHAR path[] = TEXT("explorer");
DWORD f = 0; //I tried a variety of these flags; didn't work
return CreateProcess(NULL, path, NULL, NULL, FALSE, f, NULL, NULL, &si, &pi);
}
ShellExecute
but it didn't work either.The same exact code just worked for me a couple of times, and then stopped working again... huh?
This isn't really an answer to the "why", but I managed to find out how to fix it myself:
Instead of copying environmental variables from the current process, if I copy them with CreateEnvironmentBlock
, then it works.
I still haven't figured out what's causing it, though...