3

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 asp.net 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;
    process.Start();
    // 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\
Jeroen
  • 149
  • 1
  • 9

3 Answers3

4

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.

Jeroen
  • 149
  • 1
  • 9
Nitz
  • 1,018
  • 1
  • 8
  • 18
0

If iisreset really does not work, then try restarting the W3SVC service (in services.msc). That's basically a total restart of IIS.

MichelZ
  • 11,008
  • 4
  • 30
  • 58
  • Thank you for your suggestion. I've found the "World Wide Web Publishing Service" and restarted it after changing the `PATH`, but it had no effect on my application. I checked my changes by starting a fresh command prompt which *does* show the changed path. After a reboot a fresh command prompt will still see the changed path, as will my asp.net application. For my particular scenario this suggestion unfortunately didn't work. – Jeroen Jul 14 '14 at 11:47
  • This seems to be really weird to me then... :( – MichelZ Jul 14 '14 at 11:57
0

I ran into the same issue just now and read the KB articled linked to in the answer from Nitz. This triggered me, because that article specifically mentions processes running as "Local System". In my case I run my app pools under specific user accounts (makes logging into SQL Server possible without a password in a config file) and I knew there was a setting "Load user profile" on the app pool which defaults to "false". Set that setting to true and now recycling my app pool seems to do the trick just fine.

So if you are able to run the app pool under a different user than "local system", this might solve the problem.