等待svchost.exe时,CreateProcess()和ShellExecute()会冻结

时间:2014-12-18 06:39:11

标签: winapi windows-8 createprocess shellexecute c++builder-xe5

在Windows 8下,我正在启动一个外部程序,但它会作为后台进程卡住,等待svchost.exe返回。如果我手动启动相同的应用程序(双击)它就会很好地启动。 如果我在Windows 7下运行相同的代码,它可以正常工作。

我主要尝试了3种执行应用程序的方法:

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

这返回ok,但应用程序冻结等待svchost.exe。 然后我尝试了扩展版本。

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);

这也返回ok并且我设置了hInstApp,但仍然像以前一样冻结。 然后我尝试了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);

这也返回ok并正确填充PROCESS_INFORMATION,但它仍然冻结。 RAD Studio在创建过程时显示调试消息:

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

在Windows 8任务管理器中,我可以看到进程正在等待svchost.exe返回。

0 个答案:

没有答案