Scheduled Task to do iisreset.exe

We need a scheduled task to run a console app.  This console app will perform some tests and perform an iisreset if necessary.

var proc = new Process
StartInfo = new ProcessStartInfo
FileName = @"c:\windows\system32\iisreset.exe",
Arguments = "",
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true,
Verb = "runas"

StringBuilder sb = new StringBuilder();
while (!proc.StandardOutput.EndOfStream)
logger.Info("iisreset ouput:[" + sb.ToString() + "]", LogCategory);

The scheduled task needs to run under an identity with local administrator right.  I also mark the scheduled task with “Run with highest privileges”.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s