Restrict user to stop a windows service

2019-09-20 05:41发布

I'm involved in writing a Windows Service. Before I start writing it, I'd like to know

  1. What are the points to be considered in terms of LOGIN USERS, specifically how to restrict other users from "stopping a service"?
  2. What are the generic points should I consider while writing a service?
  3. How can I display a warning alert once the user tries to stop the service?

Note: I am trying to write the service in C.

Thanks.

1条回答
干净又极端
2楼-- · 2019-09-20 06:12
  1. Normal users wont be able to stop services. It requires administration privileges.
  2. You can't do anything that involves writing to the screen or reading the keyboard/mouse.
  3. You will need to write an application that sits in the background (hidden window) and communicates with the service via some interprocess communication method (RPC/sockets etc). This application will receive a message from the service that displays a message box or otherwise communicates with the user.

I would try to write the code (for both service & application) in C# as most of the hard work (registering with SCM, start/stop etc) has been done for you.

查看更多
登录 后发表回答