从Windows服务启动explorer.exe [英] starting explorer.exe from Windows Service

查看:465
本文介绍了从Windows服务启动explorer.exe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在.Net 4.5中制作了一个Windows服务。我想通过我的服务检查是否在机器上启动了explorer.exe进程,如果没有,则启动该进程。



i听说过差异赢得服务的会话之间在会话0中运行,所有其他进程在Windows的会话1中运行。可能这就是为什么我无法从我的服务启动explorer.exe。



我到现在为止尝试过:



方法:1

I have made a windows service in .Net 4.5. I want to check if the explorer.exe process is started or not on the machine through my service and if not, then start the process.

i have heard about the difference between sessions that win service runs in session 0 and all other processes runs in session 1 of windows. may that''s why i am unable to start the explorer.exe from my service.

I have tried till now :

method : 1

<pre lang="vb">Dim pro As New ProcessStartInfo("C:\Windows\explorer.exe")
        pro.UseShellExecute = True
        Process.Start(pro)





方法:2



method : 2

Shell("C:\Windows\explorer.exe", AppWinStyle.MaximizedFocus)





方法:3



method : 3

Process.Start("C:\Windows\explorer.exe")





但是无法成功应用任何一个..请帮帮我..



but couldn''t apply any of them successfully.. please help me out..

推荐答案

你不能这样做。如果您的代码完全有效,则Explorer将在会话0中运行,对于登录桌面的用户完全不可见。实际上,IIRC,资源管理器甚至不会在第0节中启动。



从Windows Vista开始,服务无法再与用户会话进行交互。这是因为涉及到安全风险。



你无法做你想做的事。



此外,根本没有理由这样做。如果资源管理器被终止,系统将自动重启它。但是,如果Explorer无法启动,这意味着系统处于这样一个搞砸的状态,无论如何都需要重新启动。
You can''t do this. If your code worked at all, Explorer would be running in Session 0, completely invisible to the user logged in that the desktop. Actually, IIRC, Explorer won''t even launch in Session 0.

As of Windows Vista, Services can no longer interact with the users session. This is because of the security risks involved.

You cannot do what you want to do.

Besides, there''s really no reason to do this at all. If Explorer is killed off, the system will restart it automatically. If, however, Explorer fails to start, this means the system is in such a screwed up state that it needs to be restarted anyway.


当代码无法启动资源管理器时会返回什么错误?



你在做什么版本的Windows? Windows Vista及更高版本中的会话0隔离可能会影响您的方法......
What error is returned when your code fails to start explorer?

And what version of Windows are you working on? Session 0 Isolation in Windows Vista and beyond may affect your approach...

这篇关于从Windows服务启动explorer.exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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