In a Windows.NET application, to modify the remote machine configuration file that is used by the ASP.NET application. However, I keep getting the error:
System.IO.IOException: The process cannot access the file '[file name]' because it is being used by another process.
Now this is not a problem, but I suppose that if I can stop IIS, then I can change the machine configuration file (without getting an exception), and then I can restart IIS with this code:
Process proc = new Process();
proc.EnableRaisingEvents = false;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.StartInfo.FileName = "iisreset";
proc.StartInfo.Arguments = serverName;
try
{
proc.Start();
proc.WaitForExit();
...
1) Is there a way to stop IIS without restarting it, and 2) Doe this approach to changing the server.config file even make sense?
(note, I modify the file by searching and replacing regular expressions, is this a problem?)
source
share