How to recycle a state server programmatically?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I have to recyle a given application pool programmatically. I have to make a webpage that contains a button, that when there is a critical issue, i can access that URL and recyle any given application pool except the one which i am using to access this page.
I tried following script, but it wont work when site published with this code and accessed through URL.

1 - What permissions are required?
2- is the following code approach is correct?
I wrote the script command to recycle the appPool in a .bat file and called it using following code snippet.
<pre class="prettyprint using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Diagnostics;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
try
{
// // Get the full file path
// string strFilePath = Server.MapPath("batch.bat");

//Tools.Impersonator imp = new Tools.Impersonator("adam.Pascal", "MyDomain", "xxxxxxx");


string File = Server.MapPath("batch.bat");
//// Create the ProcessInfo object
//System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(File);
//psi.UseShellExecute = false;
//psi.RedirectStandardOutput = true;
//psi.RedirectStandardInput = true;
//psi.RedirectStandardError = true;

////psi.WorkingDirectory = @"%systemroot%system32inetsrv";
////psi.Arguments = strFilePath;

//// Start the process
////System.Diagnostics.Process proc = System.Diagnostics.Process.Start(psi);
//System.Diagnostics.Process.Start(psi);



//

Process proc = new System.Diagnostics.Process();

proc.StartInfo.WindowStyle = ProcessWindowStyle.Normal;

//proc.StartInfo.WorkingDirectory = Server.MapPath(".");

proc.StartInfo.UseShellExecute = true;

proc.StartInfo.FileName = File;


proc.Start();


proc.WaitForExit();

proc.Close();

//imp.Dispose();

}
catch (Exception ex)
{
Response.Write(ex.Message);



}

finally
{

}

}
}[/code]
Please help<br/>

<
Shamshad Ali
<br/>
<br/>

View the full article
 
Back
Top