开发者

How to add application folder to %PATH% after installation (VS Setup Project)

I'm looking for a easy way to include application installation folder to a %PATH% environment variable after installation is开发者_如何学Go complete.

Visual Studio 2005/2008/2010, Setup Project.

Thank you


Sad, but it still seems that you are right that it is required to code a class for the custom action. The example implementation has vanished. See below for an alternative.


This is an old question but still ranks high in google results.

The link in the accepted answer is now broken.

However, you can find a duplicate question (asked later) that still has accurate answers here: GetEnvironmentVariable() and SetEnvironmentVariable() for PATH Variable

I flagged this question as duplicate but until it is closed here is the following code that worked for me:

string keyName = @"SYSTEM\CurrentControlSet\Control\Session Manager\Environment";
//get non-expanded PATH environment variable            
string oldPath = (string)Registry.LocalMachine.CreateSubKey(keyName).GetValue("Path", "", RegistryValueOptions.DoNotExpandEnvironmentNames);
//set the path as an an expandable string
Registry.LocalMachine.CreateSubKey(keyName).SetValue("Path", oldPath + ";%MYDIR%",    RegistryValueKind.ExpandString);

I replaced %MYDIR% with the application path.

In addition, you will need to make a custom action to house this code and place the code within the commit function.


The primary issue is that Visual Studio setups don't support the Windows Installer Environment table that can do all this with PATH and other environment variables. The MSI's Environment table isn't that complex, so it's worth using an MSI editor (such as Orca) to learn how to use it, then automate the MSI update with a post build step with a script (such as WiRunSql.vbs in the Windows SDK) to automate the update.

Alternatively, learn enough WiX to create a merge module containing the environment variables your setup needs, and add it to your Visual Studio setup.

Either of these choices is better than writing runtime code that requires care not to destroy the environment variables as well as not working for user variables in an Everyone install.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜