Monday, June 22, 2009

Update the Windows Path with Visual Studio Setup and Deployment Wizard (with caveats)

Microsoft Visual Studio.NET 2003/2008 has a setup and deployment wizard which you can use to create installers for your custom applications. During the installation of your application, you might want your installer to automatically add in the path to your custom application executable to the Windows system path.

The Visual Studio setup and deployment project has a Registry Editor which you can use to get your installer to add in your application registry keys and values. For instance, by using the Registry Editor, you can add in the registry keys under HKEY_LOCAL_MACHINE to set the Windows Path.

Underneath \\HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment keys, you can add in a Environment String Path value with the string "[%Path];[TARGETDIR]", as shown below.
Once that is done, your installer will automatically set the Windows environment Path variable to include the path to your custom application's executable.

But there is a problem with this method: when you uninstall your custom application, the uninstaller will remove the Path string from the Registry. A better approach would be to create a small Custom Action program to add modify the Registry instead. I will post details about that method later here.

1 comment:

cizer said...

Honestly what is the point? I can't imagine anything more heinous than an uninstaller removing my Path variable. Glad I read to the end of this article.

Related Posts with Thumbnails