Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I restart IIS from C# code running as a user who is an administrator?

Typically (in Windows 7), installing a program will ask for permission to modify the system. As an administrator, I can give the authorization without supplying a password.

I'm trying to figure out how to take an administrator action (restart IIS) from C# code running as a user who is AN administrator, but the not THE "Administrator" account.

like image 708
Fantius Avatar asked Oct 24 '11 02:10

Fantius


1 Answers

To run a process as elevated you can use the runas verb.

Process elevated = new Process();
elevated.StartInfo.Verb = "runas";
elevated.StartInfo.FileName = "Whatever.exe";
elevated.Start();

For restarting IIS (as mentioned before) use iisreset.

Hope you find this useful.

like image 135
ZFE Avatar answered Nov 08 '22 09:11

ZFE