Can I stop IIS?

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?)

+3
source share
7 answers

- . , , , "IISADMIN" "w3svc". , , , .

ServiceController controller  = new ServiceController();
controller.MachineName = "."; // or the remote machine name
controller.ServiceName = "IISADMIN"; // or "w3svc"
string status  = controller.Status.ToString();

// Stop the service
controller.Stop();

// Start the service
controller.Start();

net stop w3svc

net stop IISADMIN

+7

. .config .
, net:

net stop w3svc

www,

net start w3svc

.

, @monkeyp

, ( ) , @RichardOD.

+4

IISRESET/STOP.

IISRESET/? .

[: "/STOP" arguments startinfo .]

+2

"iisreset/STOP", , "iisreset/START", .

+2

, wholockme unlocker, .

Update - another option is to use Process Explorer (thanks fretje) - this is a good option, as many developers have this utility on their PC.

+2
source

You can often just recycle or stop / start the IIS application pool is working, rather than restarting IIS at all.

0
source
Using System.Diagnostics;

//to stop ISS
ProcessStartInfo startInfo = new ProcessStartInfo("iisreset.exe", " /stop");
System.Diagnostics.Process.Start(startInfo);

//to start ISS
ProcessStartInfo stopInfo = new ProcessStartInfo("iisreset.exe", " /start");
System.Diagnostics.Process.Start(stopInfo);
0
source

Source: https://habr.com/ru/post/1713794/


All Articles