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

I am looking for an easy way to include the application installation folder in the% PATH% environment variable after the installation is complete.

Visual Studio 2005/2008/2010, installation project.

thanks

+4
source share
3 answers

Sadly, it still seems like you're right that you need to code the class for a custom action. An example implementation has disappeared. See below for an alternative.

+2
source

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 exact answers here: GetEnvironmentVariable () and SetEnvironmentVariable () for the PATH variable

I posed this question as a 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 perform your own action to place this code and put the code in a commit function.

+1
source

The main problem is that Visual Studio settings do not support the Windows Installer environment table, which can do all this with PATH and other environment variables. The MSI Environment table is not so complicated, so you should use the MSI editor (for example, Orca) to find out how to use it, and then automate the MSI update using the post build step using a script (for example, WiRunSql.vbs in the Windows SDK) for automation updates.

Alternatively, learn enough WiX to create a merge module that contains the environment variables that your settings need and add it to your Visual Studio setup.

Any of these options is better than writing runtime code, which requires care not to destroy environment variables, and also does not work for custom variables in the Everyone installation.

0
source

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


All Articles