开发者

CreateProcessAsUser doesn't draw the GUI

I have a windows service running under "SYSTEM" account that checks if a specific application is running for each logged in user. If the application is not running, the service starts it (under corresponding user name).

I'm trying to accomplish my goal using CreateProcessAsUser(). The service does start the application under corresponding user name, but the GUI is not drawn. (Yes, I'm making sure that "Allow service to interact with desktop" check box is enabled).

System: X开发者_Go百科P SP3, language: C#

Here is some code that might be of interest:

PROCESS_INFORMATION processInfo = new PROCESS_INFORMATION();  
startInfo.cb = Marshal.SizeOf(startInfo);  
startInfo.lpDesktop = "winsta0\\default";  
bResult = Win32.CreateProcessAsUser(hToken, null, strCommand, IntPtr.Zero, IntPtr.Zero, false, 0, IntPtr.Zero, null, ref startInfo, out processInfo);  

As far as I understand, setting startInfo.lpDesktop = "winsta0\default"; should have used the desktop of corresponding user.

Even contrary to what is stated here: http://support.microsoft.com/kb/165194, I tried setting lpDesktop to null, or not setting it at all, both giving the same result: process was started in the name of expected user and I could see a part of window's title bar. The "invisible" window intercepts mouse click events, handles them as expected. It just doesn't draw itself.

Is anyone familiar with such a problem and knows what am I doing wrong?


MSDN has a sample of how to create a process as another user setting explicit permissions on the window station and desktop objects:

CreateProcessAsUser() windowstations and desktops

You can port the code to C# using P/Invoke or you could use a C++/CLI assembly.

However, be aware that your scenario is not supported and likely to break with Vista's (and Windows 7's) Session-0 isolation (download the whitepaper on the right).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜