at last it worked...
There were a mixture of problems. I document the process here for future reference. Beware of security risks.
Thanks to Wjdavis5, I changed AppPool Identity to Local System.
Thanks to Running a batch file from an ASP .NET page, I removed some lines from code:
public string DoJob()
{
var si = new Process
{
StartInfo =
{
FileName = "shutdown.exe",
Arguments = "-r -f -t 0 -c "Shutdown Reason" -d p:4:1",
WorkingDirectory = "c:\\windows\\system32\\"
}
};
string res;
try
{
si.Start();
si.WaitForExit();
res = "<br />Minor Job done... wait 2 minutes to complete action<br />You can now close this window";
}
catch (Exception ex)
{
res = ex.Message;
}
si.Close();
si.Dispose();
return res;
}
To eliminate security risks, alongside with some security approaches in hiding website and web service, such as using subdomain and non-standard port, I made use of impersonation in A small C# Class for impersonating a User by Uwe Keim the above method content wrapped in this code:
try
{
using (new Impersonator("Admin Username", ".", "Admin Password"))
{
// Above method Content
.
.
.
}
}
catch (Exception ex)
{
return "Invalid Username or Password";
}
this code checks if provided credential is valid on server. I did not test non-administrative users on this application because this server does not have any.
feel free to comment and correct. Regards