在Visual Studio安装程序中使用Windows环境变量作为注册表值 [英] Using windows environment variables as registry values in Visual Studio Installer

查看:182
本文介绍了在Visual Studio安装程序中使用Windows环境变量作为注册表值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗯,我想使用Windows环境变量作为注册表项的值。不幸的是,我不能像%systemroot%\system32\MyScreensaver.scr



可以猜到,我想指出一些reg值到我自己的应用程序,如自动启动和屏幕保护程序等等。



任何想法?

解决方案

Windows注册表使用 REG_EXPAND_SZ 注册表值类型本机支持。



只要使用 REG_EXPAND_SZ 而不是 REG_SZ ,当你想嵌入环境变量在注册表项值中。



下面是访问 REG_EXPAND_SZ 的C#代码的示例,扩展被自动处理:

  var registry = Registry.CurrentUser.OpenSubKey(Environment); 
var temp = registry.GetValue(TEMP)as string;

以下是创建可扩展注册表值的示例:

  registry.SetValue(TEMP,@%USERPROFILE%\AppData\Local\Temp,RegistryValueKind.ExpandString); 

其他平台或脚本语言还有其他机制来支持这一点。以下是 REG_EXPAND_SZ 的低级别Win32描述:




Hey, i want to use windows environment variables as value for a registry entry. Unfortunately i can not simply write sth like %systemroot%\system32\MyScreensaver.scr.

As you can guess, i want to point some reg values to my own app, such as the auto start and screensaver and some other things.

Any ideas?

解决方案

The Windows registry supports this natively with the REG_EXPAND_SZ registry value type.

Just use REG_EXPAND_SZ instead of REG_SZ when you want to embed environment variables in the registry key value.

Here is an example of C# code accessing a REG_EXPAND_SZ and the expansion is handled automatically:

var registry = Registry.CurrentUser.OpenSubKey("Environment");
var temp = registry.GetValue("TEMP") as string;

Here is an example of creating an expandable registry value:

registry.SetValue("TEMP", @"%USERPROFILE%\AppData\Local\Temp", RegistryValueKind.ExpandString);

Other platforms or scripting languages have other mechanisms to support this. Here is the low-level Win32 description of REG_EXPAND_SZ:

这篇关于在Visual Studio安装程序中使用Windows环境变量作为注册表值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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