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.

Alex
  • 53
  • 5
  • STATUS_DLL_INIT_FAILED is specifically mentioned in [this blog post](http://blogs.technet.com/b/askperf/archive/2007/07/24/sessions-desktops-and-windows-stations.aspx) about desktops. Note how CreateDesktopEx() allows you to set the size of the desktop heap. How this is related to the service account is hard to see, possibly a dead alley. – Hans Passant Nov 19 '13 at 13:00
  • Thanks for the infrmation. I tried CreateDesktopEx() with big desktop heap, but it didn't help. – Alex Nov 20 '13 at 06:11

1 Answers1

0

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