1

I have some packages in a Folder on Azure and I want to add that path to the VM's %PATH% system variable which I have to do programmatically in order for my code to be able to use those packages. I have done adding the Folder path to the %PATH% variable using POWERSHELL commands but the problem is when you edit %PATH% you have to restart the process in order for the process to acquire the new %PATH%.

Now as I am on Azure Web Role, how do I deal with it ? Should I restart/recycle my web role using:

RoleEnvironment.RequestRecycle();

But this way the POWERSHELL script will run again and reset the %PATH% ?? Is there any other way to add a folder's path to %PATH% variable and the process uses it without having the need to restart/recycle ??

p.s. I have already tried the set/setx commands. "setx" does require the restarting and "set" just sets the path for that current session so both don't work for me.

Sarmad
  • 303
  • 3
  • 16
  • Can't you just add a new environment variable using startup task and use that variable in your code instead of modifying %PATH%? – Gaurav Mantri Oct 04 '15 at 19:15
  • Well that is doable but that won't solve my problem because I am using R and it has to search the PATH variable to find the actual path to the folder having the R-packages and all this happens in R internally which I am not handling. – Sarmad Oct 05 '15 at 09:57

1 Answers1

1

I have solved my problem. Adding answer here so that it might be useful to others.

Whenever you add a folder path to the %PATH% system variable it broadcasts a

WM_SETTINGCHANGE

message to all top-level windows in order to tell them about the changes. However the process broadcasting this message does not get the updated PATH value unless it is restarted. On Azure what I did was that I stopped the WindowsAzureGuestAgent process and started it immediately again(takes around 15-20seconds to restart) from OnStart() method of my web role.

var theController = new System.ServiceProcess.ServiceController("WindowsAzureGuestAgent");
    theController.Stop();
    theController.Start();

This way I got the updated value of PATH variable and my problem was solved.

Sarmad
  • 303
  • 3
  • 16