是否可以在安装向导项目中注册环境变量? [英] Is it possible to register environment variables in Setup Wizard project?

查看:79
本文介绍了是否可以在安装向导项目中注册环境变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的程序创建Visual Studio 2008安装向导
http://support.microsoft.com/kb/307353
我看到可以添加注册表项等. 是否可以在不编写自定义操作的情况下注册Windows环境变量?
而且,如果我必须编写自定义操作,那么最痛苦的方法是什么?

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?

推荐答案

警告 : Please do not use this approach .有危险.使用内置的MSI功能进行环境变量更新.

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

示例 :直接写入 HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment - Path 将会清除现有的内容.非常严重.

Example: Writing straight to HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment - Path will wipe out whatever is already there. Very serious.

解决方案 :MSI提供了环境表,以方便以可靠的方式合并和更新环境变量.请注意,此表也很复杂,足以触发意外的结果.请测试好.尤其是卸载方案.

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.


使用Visual Studio 2008,您可以通过在Windows注册表中设置适当的变量来轻松地做到这一点:


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

  1. 在解决方案资源管理器中,右键单击您的项目(不是解决方案),然后选择查看->注册表
  2. 创建注册表项(文件夹):
  1. In the Solution Explorer, right-click on your project (not solution), and select View->Registry
  2. Create the registry key(folder):
  1. 对于 User 变量:右键单击 HKEY_CURRENT_USER ,选择"新密钥",并将其命名为"环境".
  2. 对于 System 变量:右键单击 HKEY_LOCAL_MACHINE ,选择"新密钥",并将其命名为" SYSTEM ".继续执行此操作以创建路径" HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ Session Manager \ Environment ".
  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_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" .

  • 右键单击环境键(文件夹),选择 New-> String ,并为其指定名称.
  • 选择字符串后,找到属性窗口(Alt + Enter会弹出该窗口)
  • 在属性"窗口中,填写所需的.
  • Right-click on the Environment key(folder), select New->String, and give it the name you want.
  • With the string selected, find the Properties window (Alt+Enter will bring it up)
  • In the Properties window, fill in the Value you want.
  • 如果要让Value引用安装目录,则可以使用属性变量执行以下操作:[TARGETDIR] SomeFile.ext(请参阅

    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)

    这篇关于是否可以在安装向导项目中注册环境变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆