Wednesday - VS2008, Vista SP1.
I wrote a process management service that can run applications either in session 0 or in an interactive console (usually 1). Please note that this is NOT a normal mode of operation, it is intended for internal debugging purposes only. In the field, these processes will be safely hidden in session 0. Security problems are not applied.
It is clear that people do not read this: security problems do not apply. We have dozens of existing server applications (NOT services) written as follows. We are not going to completely update these applications, we just need to be able to enter their built-in debug dialogs when launching release versions within the company. I already know everything about the canonical solution and pipes, etc. If it was acceptable to add remote interfaces to all these applications, this is what we will do.
For this, I use the following code:
ZeroMemory (&sui, sizeof(STARTUPINFO)); sui.cb = sizeof (STARTUPINFO); sui.wShowWindow = pTask->GetWinStartState() ; sui.dwFlags = STARTF_USESHOWWINDOW ; ZeroMemory (&pi,sizeof(pi)); if (bInteractive) { HANDLE hToken = NULL; DWORD dwSessionId = WTSGetActiveConsoleSessionId(); WTSQueryUserToken (dwSessionId, &hToken); sui.lpDesktop = TEXT("winsta0\\default"); LPVOID pEnv = NULL; DWORD dwCreationFlag = NORMAL_PRIORITY_CLASS | CREATE_NEW_CONSOLE; HMODULE hModu = LoadLibrary(TEXT("Userenv.dll")); if (hModu ) { if (CreateEnvironmentBlock (&pEnv, hToken, FALSE)) dwCreationFlag |= CREATE_UNICODE_ENVIRONMENT; else pEnv = NULL; } bCreatedOk = CreateProcessAsUser (hToken, NULL, (LPTSTR)(pTask->GetExeName()), NULL, NULL, FALSE, dwCreationFlag, pEnv, NULL, &sui, &pi); } else { bCreatedOk = CreateProcess (NULL, ... blah...); }
All this works fine, and I can start and control my own processes both in the Vista service session and in the console. Fine. Cakes and ale for everyone.
So here is the problem. If I try to run the winforms (C #) application in an interactive mode similar to this, it will be launched, it appears in Process Explorer as running in session 1, but on the desktop ... nada. The window is missing. The process starts and stops normally, but the window never appears. Exactly the same winform exe launched from Explorer also appears in session 1, but this time on the desktop itβs just fine.
Any ideas?
c ++ winapi winforms windows-services
Bob moore
source share