Temporarily updating Environment Variable - PATH

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

[Using C# .Net 1.1]

I need to update the PATH environment variable for the lifetime of my .Net
process only - I'm pinvoking my own C++ dlls and they are not always in the
same dir as my .Net app. [ I dont want to update the Windows PATH environment
variable. ] Is this possible with .Net code - the Environment class doesnt
have set methods/properties ?

If not then I suppose I can always pinvoke and use "SetEnvironmentVariable"
from Kernel32.dll.

Thanks,
RichS
 
RichS said:
Hi,

[Using C# .Net 1.1]

I need to update the PATH environment variable for the lifetime of my .Net
process only - I'm pinvoking my own C++ dlls and they are not always in the
same dir as my .Net app. [ I dont want to update the Windows PATH environment
variable. ] Is this possible with .Net code - the Environment class doesnt
have set methods/properties ?

If not then I suppose I can always pinvoke and use "SetEnvironmentVariable"
from Kernel32.dll.

Thanks,
RichS


I use such method.

Create a dummy wrapper application to run the main application.

//example in C#
//in wrapper application main()
Process pp=new Process();
string epath=pp.StartInfo.EnvironmentVariables["PATH"];
epath += (";"+PathYouWantToAdd);
pp.StartInfo.EnvironmentVariables["PATH"]=epath;

pp.StartInfo.FileName=YouMainApplication;
.... //other setting
pp.Start();

//after start the main app, wrapper application quit.

Then, the "PATH" just affect your main application.
 
Back
Top