0

Under Windows 8 I'm starting an external program but it get stuck as a background process waiting for svchost.exe to return. If I start the same application manually (double click) it starts just fine. If I run the same code under Windows 7, it works just fine.

I have mainly tried 3 ways of executing the application:

ShellExecute(NULL,L"open","MyApp.exe",NULL,NULL,SW_SHOWNORMAL);

This returns ok but the application freeze waiting for svchost.exe. Then I tried the Extended version.

SHELLEXECUTEINFO ShExecInfo;

ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = Application->MainFormHandle;
ShExecInfo.lpVerb = L"open";
ShExecInfo.lpFile = L"MyApp.exe"
ShExecInfo.lpParameters = NULL;
ShExecInfo.lpDirectory = L"MyWorkDir";
ShExecInfo.nShow = SW_SHOWNORMAL;
ShExecInfo.hInstApp = NULL;

res = ShellExecuteEx(&ShExecInfo);

This also returns ok and I hInstApp is set, but still freeze as before. Then I tried CreateProcess().

STARTUPINFO si;
PROCESS_INFORMATION pi;

ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));

res = CreateProcess(L"MyApp.exe",NULL,NULL,NULL,false,0,NULL,L"MyWorkDir",&si,&pi);

This also returns ok and the PROCESS_INFORMATION is filled in correctly, but still it freeze. RAD Studio shows a debug message when I create the process:

Application "\??\C:\Windows\Program Files (x86)\ ... MyApp.exe" found in cache
Application "\??\C:\Windows\Program Files (x86)\ ... MyApp.exe" cache bypassed reason 0x86

In Windows 8 Task manager I can see that the Process is waiting on svchost.exe to return.

Max Kielland
  • 5,627
  • 9
  • 60
  • 95
  • Where in task manager shows you that it's waiting on svchost.exe ? – Jonathan Potter Dec 18 '14 at 08:11
  • In the "Information" tab, right click on the main process and select "Analyze". It will show what process it is waiting for. – Max Kielland Dec 18 '14 at 08:13
  • Sounds like you're running the parent process in a debugger? What happens if you don't? – Harry Johnston Dec 18 '14 at 22:08
  • @HarryJohnston The above problem description applies to both stand alone and debugger, no difference. Let me remind you that this works perfectly well under Windows 7 and Vista. – Max Kielland Dec 19 '14 at 01:02
  • Any chance UAC elevation is involved? Can you break into the child process with a debugger, to see what state it's in? Is this happening with *any* child process, or just this specific one? – Harry Johnston Dec 19 '14 at 01:05
  • @HarryJohnston No it's an external application from a third party. svchost.exe is assigned by Windows to host services used by the application. I'm not quite sure, but I think it is hosting an RPC call in this case. If i kill the svchost.exe process, the application starts but, of course, crash the whole windows a few seconds later. I have tried to run my host app as administrator but no difference. Maybe it has to do something with inherited handlers? – Max Kielland Dec 19 '14 at 04:45
  • There really isn't all that much that child processes inherit. You're passing through the same environment variables that you were given, so that's OK. You should double-check that the current directory is the same in both cases. The only other thing I can think of is that the app might be unusually sensitive to the command line, e.g., it must (or perhaps must not!) contain the full path to the executable, I don't recall offhand what Explorer does when you double-click. (Or there might be some new Windows 8 weirdness going on that I'm not familiar with yet.) – Harry Johnston Dec 19 '14 at 22:24
  • Process Explorer might be useful; you could compare the process details when you launch the third-party process directly with those when you launch it from your host application. If nothing else, it would be an easy way to double-check that the command line and current directory are identical. – Harry Johnston Dec 19 '14 at 22:26

0 Answers0