views:

73

answers:

1

I'm writing an installer module and I need to add a value to the system %PATH% variable permanently. How can I modify it from the C# installer code?

+4  A: 

Well, that's quite yucky. Modifying the PATH is about as evil a thing an installer could ever do. It has gotten a particularly bad rap because so many uninstallers destroy it, causing very hard to diagnose problems.

I think you'll need to write a custom action that modifies the registry. The system environment is stored in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment, Path value. You should force a reboot to make sure the new setting is effective.

And test the uninstall.


Seeing your comment to SLaks, use HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths instead.

Hans Passant
@C.Ross: Notice that even Visual Studio doesn't attempt this. And often I wish that it did sometimes (I have a habit of forgetting to run the VS Command Prompt shortcut).
Tergiver
... though something called "Roxio" has done it on this Dell Buisiness machine I'm sitting at right now (not my personal rig).
Tergiver