简体   繁体   English

Windows后台服务可按需杀死进程

[英]Windows background service to kill processes by name on demand

I want to write a simple background service that can kill all instances of a certain process for all users on demand. 我想编写一个简单的后台服务,该服务可以按需杀死所有用户的某个进程的所有实例。 The process will always be the same (Microsoft Access). 该过程将始终是相同的(Microsoft Access)。 The idea is that users without administrative rights are able to execute a script, which tells the background service to kill the processes before moving on with other tasks. 这个想法是,没有管理权限的用户可以执行脚本,该脚本告诉后台服务在继续执行其他任务之前先杀死进程。 I do have a small program written in C which is able to kill all processes when executed from the Local System account, but I'm not sure how to turn it into a service that can be triggered on demand. 我确实有一个用C编写的小程序,当从本地系统帐户执行该程序时,该程序可以杀死所有进程,但是我不确定如何将其转变为可以按需触发的服务。 Any suggestions are welcome. 欢迎任何建议。 Also, I'm open for any other way of killing all instances of a process for all users without administrative rights. 另外,我愿意以其他任何方式杀死所有没有管理权限的用户的进程的所有实例。

You can create a service from an executable using a tool such as SrvStart (you can find on this page ) and the windows command line tool sc.exe . 您可以使用诸如SrvStart (在此页面上找到)之类的工具和Windows命令行工具sc.exe从可执行文件创建服务。 Here is a tutorial that will help you to do so. 是一个可以帮助您做到一点的教程。

In order to "talk" to the service, you will need to implement some inter-process communication mechanism so that a client (script or so) runned with user priviledge ask the service to do the job. 为了与服务“对话”,您将需要实现某种进程间通信机制,以便以用户权限运行的客户端(脚本或类似脚本)要求服务执行该工作。 There are plenty of ways to do this... See this page for what you can use. 有很多方法可以执行此操作...有关可用内容,请参见此页面

Another way is to get rid of your C executable and make a windows .NET service in C# instead. 另一种方法是摆脱C可执行文件,改为使用C#创建Windows .NET服务。 In this service, override the ServiceBase.OnCustomCommand . 在此服务中,重写ServiceBase.OnCustomCommand Then you will be able to send a custom command to your service using the windows command line tool sc.exe . 然后,您将能够使用Windows命令行工具sc.exe将自定义命令发送到您的服务。

On the other hand, if what you need is only to run an executable with administrator priviledge from a user account, without password, there is a way to create a shortcut that does this. 另一方面,如果您只需要从用户帐户运行具有管理员权限的可执行文件,而无需输入密码,则有一种方法可以创建执行此操作的快捷方式。 See this page for details on how to make such a shortcut. 有关如何制作此类快捷方式的详细信息,请参见此页面

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM