System Administration & Network Administration
iis windows-server-2012 environment-variables
Updated Sun, 24 Jul 2022 02:20:23 GMT

How to "recycle" the IIS process without rebooting the server?

Getting ASP.NET to see changes in PATH
I've changed the environment PATH variable on my server and need IIS / W3WP (i.e. my ASP.NET app) to see this change. I understand from this other question's answer that (emphasis mine):

You'll have to recycle the IIS process to get it to update

My question: how do I "recycle" the IIS process?

Here are the things I've tried to solve this issue:

  • Use iisreset
    I've tried a few things. First thing I tried was iisreset, but my app did not pick up the path changes. To make sure I wasn't crazy I tried rebooting the server, which did work: the app now picks up the new PATH.

    I'd love to know if there's a way I can prevent needing to reboot the entire machine just because I want my PATH changed in my ASP.NET application...

    One other thing that may be the case is that I misunderstood the other question (that the answerer there did mean iisreset when saying "recycle iis")? That doesn't explain why iisreset did not work for my situation, and rebooting the server did. Are there options for iisreset that I'm missing?

  • Searching the interwebs
    I've also tried searching for solutions. From my first searches about my PATH issues led to no real info (except aforementioned question). My second set of searches about recycling the IIS process don't work to well: I get info about iisreset and how it may recycle worker processes.

  • Restarting W3SVC
    An answerer suggested restarting W3SVC (the "World Wide Web Publishing Service"), which seemed promising, but it also didn't work for me (it might work for you though!). I tried that suggestion by changing the path, using a fresh command prompt to verify the change came through, and restarted W3SVC: no dice for my ASP.NET application. After a reboot a fresh command prompt will still show the changed path, and my application will also see the change (so the change itself was in fact what I wanted).

    Another answerer suggested something similar, with one important difference: let the service remain stopped for a little bit, confirm in between that the site is unavailable (to see it's actually IIS serving that site). This had the same result for me though.

  • Killing the correct IIS process On a foot note, one final alternative I've considered is killing the svchost process for iis, as that seems like a rather brute solution. I've tried this and killed "svchost.exe -k iissvcs", but this didn't work either. But perhaps I just killed the wrong process.

  • Changing the AppPool settings
    The application pool for my app had a non-default setting "Load User Profile = False" running under the the NetworkService identity. I'm unsure (even after reading the inline explanation) what the setting does, but I could imagine it had some effect on the PATH variable as seen by my app. Alas, setting it to True didn't solve anything.

To add some final details just in the off case that they're important. In my scenario I'm trying to start bcp.exe with something along these lines:

using (var process = new Process()) 
    process.StartInfo.FileName = "bcp.exe";
    process.StartInfo.Arguments = myArguments;
    process.StartInfo.UseShellExecute = false;
    // Code to handle the process exiting and use the output.

We require BCP version 11 but had version 10 on the server box. The tool has a standalone installer, which adds the following crucial bits to the PATH:

  • C:\Program Files\Microsoft SQL Server\110\Tools\Binn
  • C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\


This is impossible.

Environment variables are inherited from parent processes (up to the login process) in all modern OSes (afaik), if you change a variable you have to make sure the session the process is running in is restarted (kind of logging off and on).

Since IIS is based off services.exe, you can't really do that without restarting (killing services.exe is verboten).

Here is a KB about it.

Comments (2)

  • +0 – Updated answer. Didn't read your question with enough attention I guess... — Jul 14, 2014 at 13:47  
  • +0 – Ahhh... that makes sense. Thank you for the update and the KB article. — Jul 14, 2014 at 13:55