从Windows服务中删除进程 [英] killing a process from windows service

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

问题描述

我试图让explorer.exe杀死直到活动。



我的意思是我有一个xml文件,我从我的Windows服务后台工作者那里读取。为了安全起见,它等待一个值,直到explorer.exe不应该执行为止。



我到现在为止尝试过:



I am trying to keep the explorer.exe KILLED till an event.

I mean i have an xml file which i read from my windows service background worker. It waits for a value, till than the explorer.exe should not execute, its for security purpose.

I have tried till now :

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一次,但是要探索r.exe自动打开,服务无法再次杀死它。



错误:Accecss被拒绝。



如果它的一些权限问题比第一次杀死它怎么样?



代码是否有任何问题???



this code is written in backgroundWorker''s doWork() event.

my windows service will check for a value in xml database, if its 0 then it will check if explorer.exe is started or not, if yes than kill it.

if the value in xml file i found 1 than it will check if explorer.exe is started or not, if not than start it.

Problem : when i start the service, it kills the explorer.exe once, but explorer.exe open automatically and the service fails to kill it again.

Error : Accecss is denied.

if its some permission problem than how would it killed first time ??

Is there any problem with the code ???

推荐答案

我认为你不能永久杀死explorer.exe。它是Windows操作系统的关键部分。如果您想要对硬盘驱动器必须具有的数据进行一些安全保护,请考虑使用.NET Framework命名空间 System.IO.IsolatedStorage 命名空间中可用的类或加密将数据写入磁盘时的数据。
I don''t think you can permanently kill explorer.exe. It is a key part of the Windows operating system. If you want some security over data that you must right to the hard drive, please consider using the classes available in the.NET Framework Namespace System.IO.IsolatedStorage namespace or encrypting the data as you write it to disk.


您无法可靠地杀死Explorer.exe。这是Windows认为的关键过程。你可以杀死它,但它会反复重新启动。不断杀死进程可能导致系统不稳定。



更好的解决方案是没有人登录控制台。
You can''t reliably kill Explorer.exe. It''s what Windows considers a "critical process". You can kill it, but it''ll repeatedly be relaunched. Constantly killing the process can lead to system instability.

The better solution is to not have someone logged in at the console.


这篇关于从Windows服务中删除进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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