Below is the code using which we can IISRESET on the remote servers list through C# (Windows Form implementation approach which consumes psutil.bat to do iisreset)-
string[] textlines = textBox1.Lines;
string servername;
String[] serverstatus = new String[20000];
textBox2.Lines = serverstatus;
int i = 0;
foreach (string line in textlines)
{
servername = line;
try
{
string[] args = { servername, "reset" };
Process.Start("psutil.bat", String.Join(" ", args));
string tmp = servername + " check command prompt";
serverstatus[i] = tmp;
}
catch (Exception ex)
{
string tmp = servername + " check command prompt";
serverstatus[i] = tmp;
}
i++;
}
textBox2.Lines = serverstatus;
I have used PSutil.bat in C# for calling PsExec.exe given by Microsoft.Â
-------------------------------------------------------------------------------------
if %2==stop goto A
if %2==start goto B
if %2==reset goto C
:A
PsExec.exe \\%1 iisreset /stop
goto END
:B
PsExec.exe \\%1 iisreset /start
goto END
:C
PsExec.exe \\%1 iisreset /restart
goto END
:END
pause
-----------------------------------------------