简体   繁体   中英

Starting windows service programatically using impersonation

I've been searching for an answer for my problem for hours but after trying lots of suggestion I'm still stuck.

I have a C# Windows form based application I work on and I have to launch a windows service (also part of the solution) programatically (when the user clicks the appropriate button). This part is already in place - I can launch the service but... I have some problems in Windows 7 and 2008 Server.

The problem is that I can't do it as my application is loaded by the machine administrator but as a filtered standard and not as full administrator ( more info here ). If we launch the application as Administrator it works fine, but I don't want to bother the user to do it every time.

I would like to know if it is possible to pop the Windows confirmation screen when the user enters the form where he can start the service - as a full administrator.

Any ideas?

Thanks

IIRC - you can't elevate an existing processes privileges, you would need to spawn a new process to perform the operation which requires it.

Found a previous question which further explains this.

You can either launch another application thorugh ShellExecute (using the runas verb) so Windows would prompt the user or use the COM Elevation Moniker (both when the user clicks on the button).

If you are targeting Windows Server 2008 R2/Windows 7 maybe you can use Service Trigger Events .

Best

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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