Sarmad
Sarmad

Reputation: 323

Set System variable %PATH% in azure web role

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.

Upvotes: 1

Views: 231

Answers (1)

Sarmad
Sarmad

Reputation: 323

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.

Upvotes: 1

Related Questions