是否可以在安装向导项目中注册环境变量? [英] Is it possible to register environment variables in Setup Wizard project?
问题描述
我正在为我的程序创建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:
- 在解决方案资源管理器中,右键单击您的项目(不是解决方案),然后选择查看->注册表
- 创建注册表项(文件夹):
- In the Solution Explorer, right-click on your project (not solution), and select View->Registry
- Create the registry key(folder):
- 对于 User 变量:右键单击 HKEY_CURRENT_USER ,选择"新密钥",并将其命名为"环境".
- 对于 System 变量:右键单击 HKEY_LOCAL_MACHINE ,选择"新密钥",并将其命名为" SYSTEM ".继续执行此操作以创建路径" HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ Session Manager \ Environment ".
- For a User variable: Right-click on HKEY_CURRENT_USER, select "New Key", and name it "Environment".
- 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" .
如果要让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屋!