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();
proc.Start();
while (!proc.StandardOutput.EndOfStream)
{
sb.AppendLine(proc.StandardOutput.ReadLine());
}
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”.

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s