我试图保持explorer.exe KILLED直到事件。
我的意思是我有一个XML文件,我从我的Windows服务后台工作人员读取。 它等待一个值,直到explorer.exe不应该执行,为了安全目的。
我一直尝试到现在:
While (True) Dim doc As New XmlDocument doc.Load("C:\Users\Alpha-Guy\AppData\Local\Packages\new-design_sa0tb4645bqbp\LocalState\metadata.xml") Dim list = doc.GetElementsByTagName("authenticated") var_auth = list(0).InnerText If var_auth = "0" Then Dim pro As Process pro = Process.GetProcessesByName("explorer")(0) If pro IsNot Nothing Then pro.Kill() End If End If If var_auth = "1" Then Dim pro As Process pro = Process.GetProcessesByName("explorer")(0) If pro Is Nothing Then Process.Start("c:\windows\explorer.exe") End If 'Try ' pro = Process.GetProcessesByName("explorer")(0) 'Catch ex As Exception ' Process.Start("c:\windows\explorer.exe") 'End Try End If End While
此代码是在backgroundWorker的doWork()事件中编写的。
我的Windows服务将检查xml数据库中的值,如果它的0,那么它将检查explorer.exe是否启动,如果是的,比杀死它。
如果xml文件中的值我发现1比它会检查explorer.exe是否启动,如果不是,则启动它。
问题:当我启动服务时,它会一次杀死explorer.exe,但是explorer.exe会自动打开,并且服务无法再重新启动。
错误:Accecss被拒绝。
如果它的一些权限问题比第一次被杀死?
有没有问题的代码?
使您的程序/服务以管理员身份运行(或SYSTEM帐户,或更高的smtg)。
我想你可以在“安装”服务的时候这样做。 那么你不会得到这个错误。
如果您不希望在从Visual Studio运行服务时遇到此错误,请以管理员身份运行Visual Studio。
我认为这会帮助你。 祝你好运!