I have a Windows service (running on Windows Vista+), which needs to launch a normal GUI application. For some reason, I need to run the GUI application on non-default desktop (of course, since it's launched by the service process, it runs in Session 0, WinSta0, but not on the Default desktop).
The code looks like this.
// create new desktop
hDesktop = CreateDesktop(NEW_DESKTOP, 0, 0 ,0,
DESKTOP_SWITCHDESKTOP | DESKTOP_WRITEOBJECTS |
DESKTOP_READOBJECTS | DESKTOP_ENUMERATE |
DESKTOP_CREATEWINDOW | DESKTOP_CREATEMENU|
DESKTOP_HOOKCONTROL, &sa);
// create process of the normal GUI application,
// running on the new desktop, not the default one
STARTUPINFO si;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
si.lpDesktop = NEW_DESKTOP;
ZeroMemory(&processInfo,sizeof(processInfo));
BOOL bRet = CreateProcess(NULL, &commandLine, NULL, NULL,
FALSE, 0, NULL, NULL, &si, &processInfo);
TCreateProcess(...) method returns successfully, but the GUI application exits immediately after launching. With help from Gflags, I got following information.
LdrpInitializeRoutines - Error: Init routine 7595D711 for DLL "C:\Windows\system32\USER32.dll" failed during DLL_PROCESS_ATTACH
_LdrpInitialize - ERROR: Process initialization failed with status 0xc0000142
LdrpInitializationFailure - ERROR: Process initialization failed with status 0xc0000142
I searched for a while, seems it's related to security issue. I tried to grant all desktop related rights to current user, but it didn't help.
One thing may help. I noticed that there are a few DLLs were not loaded when running with SYSTEM account, the first one is uxTheme.dll.
Anyone has any idea why it doesn't work with non-default desktop, while working well with default desktop?
Thanks.
You need to use CrateDesktopEx and increase the size of heap -- the default is not sufficient even for the notepad.
User contributions licensed under CC BY-SA 3.0