Cannot access Windows environment variable using C #

I created the installer using WiX. One thing the installer does is set the PLUGIN_DIRECTORY environment variable (it is at the system level).

Inside some C # code that I wrote, I need to access this variable so that I can look at a specific directory. I do this through the following code:

FileSystemWatcher water = new FileSystemWatcher();
watcher.Path = Environment.GetEnvironmentVariable("PLUGIN_DIRECTORY") + "\\";

Unfortunately (and when I am debugging), everything watcher.Path is set to "\".

Do I need to reboot after installation? I would not understand why, since the variable is already set. Any other suggestions? I don't get any errors - it just doesn't look the right way.

thanks

+3
source share
4 answers

, , , , VS. , . , VS , , , , , .

+9

, PLUGIN_DIRECTORY -, ?

0

, , , . : watcher.Path = Environment.GetEnvironmentVariable( "% PLUGIN_DIRECTORY%" ) + "\";

,% PLUGIN_DIRECTORY% PLUGIN_DIRECTORY.

,

0

, .

We can update the process environment using the boot environment from the โ€œmachineโ€ and save the โ€œprocessโ€.

string SysEnvir = System.Environment.GetEnvironmentVariable("Path", EnvironmentVariableTarget.Machine);

System.Environment.SetEnvironmentVariable("Path", SysEnvir, EnvironmentVariableTarget.Process);
0
source

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


All Articles