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). 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. 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.
-
I haven't done it, but [this](http://stackoverflow.com/a/18637556/5095502) looks like a simple way to talk to a service. Instead of running a "script", you will have to write a very small second program that sends the `sc.ExecuteCommand()` to your service. – Quantic Jun 23 '16 at 16:17
-
Thanks, I will look into it! – Jun 24 '16 at 10:11
1 Answers
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
. 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. In this service, override the ServiceBase.OnCustomCommand. Then you will be able to send a custom command to your service using the windows command line tool 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.

- 4,449
- 2
- 22
- 38
-
Thanks. My executable only works when executed by Local System, because otherwise it will only terminate processes owned by the account from which the executable is executed. I will look into your other suggestions! – Jun 24 '16 at 10:11