I made an application that requires functionality to run iisreset.exe. My application is on deploy in server. so iisreset should be server not client machine. I use process.start() but it reset iis of client machine. what code i should modify.
Asked
Active
Viewed 6,975 times
2
-
1So let me get this straight. You want an asp.net application that will restart itself, then return a message to the browser? How is it supposed to return /after/ it's been restarted? You can accomplish this if you use client-side script to check the status of the iisreset. But it's usually a bad idea to give the web application administrative privs. – agent-j Jul 12 '11 at 00:54
-
in my application many usertype. only adminstrator user type can do iisreset. client run application . I have problem that i have to reset server computer not client computer. How can i do this. – chetan singhal Jul 12 '11 at 02:03
2 Answers
4
Use the Process
class to execute a process.
How To: Execute command line in C#, get STD OUT results
// Start the child process.
Process p = new Process();
// Redirect the output stream of the child process.
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "YOURBATCHFILE.bat";
p.Start();
// Do not wait for the child process to exit before
// reading to the end of its redirected stream.
// p.WaitForExit();
// Read the output stream first and then wait.
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();

Community
- 1
- 1

Samuel Neff
- 73,278
- 17
- 138
- 182
-
samuel thanks. but problem is that client run application on client side i have to reset iis of server computer. How can i do this. But your code i thing reset client computer only. – chetan singhal Jul 12 '11 at 02:04
-
-
@cpsinghal, ah, you want to run a remote process. That is different. You could try searching for remote process on google and you'll probably find the answer quick or you could just do `iisreset /?` and see that you're making the problem significantly harder than you need to. – Samuel Neff Jul 12 '11 at 03:15
-
It works on my local machine, but when I upload the same code on the server nothing happen when click on the web link to run the bat file. – Diganta Kumar Aug 08 '13 at 07:02
-
@DigantaKumar, it's a permissions problem. You don't really want to give asp.net user too much permissions. Better to either create a scheduled task that is run manually that just restarts iis and give asp.net user specific permission to run this scheduled task. Then run the scheduled task as needed. Safer since permissions is more isolated. – Samuel Neff Aug 09 '13 at 01:32
2
Use Process.Start()
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.start.aspx
Tie into the OnExited event to get when it exits.
Further, consider the impact iisreset
has on the system as a whole. If others run sites on that same server, they may not be too happy with your software.

jglouie
- 12,523
- 6
- 48
- 65