简体   繁体   中英

How to avoid UAC when using ServerManager to read IIS sites

I am using ServerManager within Microsoft.Web.Administration to read and operate on IIS sites. This unfortunately seems to require UAC, is there a way around this or do I just have to accept that I will have to ask my user for permission before doing this?

var server = new ServerManager();
var site = server.Sites.FirstOrDefault(s => s.Name == "websiteName");
site.Stop();

You could do 2 things, if your program is Autonomous, you can set is up aa scheduled task and set it to run as "SYSTEM"

or, if you need to be able to interact with the application you could build a console application that actually does all the work, run that application all the time starting it like above as a scheduled task running as system.

That can be called MyAppService (although you dont have to build a server application, console app is fine)

Then, build an app that has all the button various functions you'd like to do and have it request the work to be done by the MyAppService. This second application can be run as a standard user because all the elevated work is done by the service.

I've done it before through Named Pipes and it worked a treat.

I hope that makes sense!

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