Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

visual studio - Is it possible to register environment variables in Setup Wizard project?

I am creating a Visual Studio 2008 Setup Wizard for my program
http://support.microsoft.com/kb/307353
I see that it is possible to add registry entries, etc.. Is there a possibility to register windows environment variable without writing a custom action?
And if I must write a custom action, what is the least painful way to do so?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Warning: Please do not use this approach. It is dangerous. Use built-in MSI features for environment variable update.

Example: Writing straight to HKLMSYSTEMCurrentControlSetControlSession ManagerEnvironment - Path will wipe out whatever is already there. Very serious.

Solution: MSI features the Environment table to facilitate merging and updating of environment variables in a reliable fashion. Note that this table is also known to be complex enough to trigger unexpected results. Please test well. Uninstall scenarios especially.


Using Visual Studio 2008, you can easily do it by setting the appropriate variable in the Windows registry:

  1. In the Solution Explorer, right-click on your project (not solution), and select View->Registry
  2. Create the registry key(folder):
    1. For a User variable: Right-click on HKEY_CURRENT_USER, select "New Key", and name it "Environment".
    2. For a System variable: Right-Click on HKEY_LOCAL_MACHINE, select "New Key", and name it "SYSTEM". Continue doing this to create the path "HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlSession ManagerEnvironment" .
  3. Right-click on the Environment key(folder), select New->String, and give it the name you want.
  4. With the string selected, find the Properties window (Alt+Enter will bring it up)
  5. In the Properties window, fill in the Value you want.

If you want the Value to reference the installation directory, you can do it like this using property variables: [TARGETDIR]SomeFile.ext (see http://msdn.microsoft.com/en-us/library/aa370905%28v=vs.85%29.aspx for more property variables)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...