CreateProcessAsUser不绘制图形用户界面 [英] CreateProcessAsUser doesn't draw the GUI

查看:440
本文介绍了CreateProcessAsUser不绘制图形用户界面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在系统运行来检查,如果一个特定的应用程序正在运行的每个登录的用户帐户窗口服务。如果应用程序没有运行,该服务启动时,它(下相应的用户名)。
我试图完成使用CreateProcessAsUser我的目标()。该服务不会开始下相应的用户名中的应用,但是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).

系统:XP SP3,语言:C#

System: XP SP3, language: C#

下面是一些code可能会感兴趣的:

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);  

据我了解,设​​置startInfo.lpDesktop =winsta0 \默认;应该用对应用户的桌面。
甚至相反这里所指出: http://support.microsoft.com/kb/165194 ,我尝试设置lpDesktop为空,或者不设置它在所有,既赋予相同的结果:过程开始于预期的用户的名字,我能看到窗口的标题栏的一部分。 看不见的窗口拦截鼠标点击事件,处理它们的预期。它只是不绘制自身。

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有如何创建一个进程作为另一个用户在窗口站和桌面对象设置显式权限的例子:

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和台式机

CreateProcessAsUser() windowstations and desktops

您可以端口code到C#使用P / Invoke或者你可以使用C ++ / CLI装配。

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

不过,要知道,不支持您的方案,并可能与Vista的(和Windows 7的)的会话0隔离 (下载右边的白皮书)。

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).

这篇关于CreateProcessAsUser不绘制图形用户界面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆