How to run c# application with admin creds?

后端 未结 7 783
旧时难觅i
旧时难觅i 2020-12-19 08:03

I wrote a C# application that unlocks users when they are locked out of their account (Active Directory). The application searches for users in a specific OU and will list t

7条回答
  •  天命终不由人
    2020-12-19 08:22

    You cannot use a Windows Service (easily), since a Windows Service cannot have a GUI. The only way to do this as a service would be to install the service, and then make a GUI app that used IPC to communicate the request to the service. This would open up a potential loophole, though.

    If you're running on Vista, a good option would be to edit the manifest file and add requireAdministrator.


    Edit:

    It sounds like my first suggestion may be what you want... To do this, the basic process is:

    • Make your application a windows service. There is a walkthrough of this process on MSDN.
    • Make your service respond to some form of IPC. You could use sockets, pipes, or any other form of communication. The service would "listen" for a request to unblock a user, then perform this.
    • Install the service on the machine. This will make it run as an administrator, and just be always on.
    • Make a second application to act as a client. Use the same IPC technology to communicate with the server. This would send the request to unblock the client to the service.

    You could then run the client as a normal user (since it just needs to talk to the service, it does not do anything that requires permissions).

提交回复
热议问题