Failed to load user32.dll when launching a process running in non-default desktop in Session 0 Winsta0

0

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.

windows
session
service
desktop
uxtheme
asked on Stack Overflow Nov 19, 2013 by Alex • edited Nov 20, 2013 by Alex

1 Answer

0

You need to use CrateDesktopEx and increase the size of heap -- the default is not sufficient even for the notepad.

answered on Stack Overflow Aug 24, 2016 by Yuriy Look

User contributions licensed under CC BY-SA 3.0