visual-studio Visual Studio 安装项目 - 每用户注册表设置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/810/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Visual Studio Setup Project - Per User Registry Settings
提问by Ray
I'm trying to maintain a Setup Project in Visual Studio 2003(yes, it's a legacy application). The problem we have at the moment is that we need to write registry entries to HKCUfor every user on the computer. They need to be in the HKCUrather than HKLMbecause they are the default user settings, and they do change per user. My feeling is that
我正在尝试维护一个安装项目Visual Studio 2003(是的,它是一个遗留应用程序)。我们目前的问题是我们需要为HKCU计算机上的每个用户编写注册表项。它们需要在HKCU而不是HKLM因为它们是默认用户设置,并且它们确实会根据用户进行更改。我的感觉是
- This isn't possible
- This isn't something the installer should be doing, but something the application should be doing (after all what happens when a user profile is created after the install?).
- 这是不可能的
- 这不是安装程序应该做的事情,而是应用程序应该做的事情(毕竟在安装后创建用户配置文件时会发生什么?)。
With that in mind, I still want to change as little as possible in the application, so my question is, is it possible to add registry entries for every user in a Visual Studio 2003setup project?
考虑到这一点,我仍然希望在应用程序中尽可能少地更改,所以我的问题是,是否可以为Visual Studio 2003安装项目中的每个用户添加注册表项?
And, at the moment the project lists five registry root keys (HKEY_CLASSES_ROOT, HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, HKEY_USERS, and User/Machine Hive). I don't really know anything about the Users root key, and haven't seen User/Machine Hive. Can anyone enlighten me on what they are? Perhaps they could solve my problem above.
而且,目前该项目列出了五个注册表根键(HKEY_CLASSES_ROOT, HKEY_CURRENT_USER,HKEY_LOCAL_MACHINE,HKEY_USERS,和用户/机器配置单元)。我对用户根密钥一无所知,也没有看到用户/机器配置单元。谁能告诉我它们是什么?也许他们可以解决我上面的问题。
采纳答案by Michael Stum
First: Yes, this is something that belongs in the Application for the exact reson you specified: What happens after new user profiles are created? Sure, if you're using a domain it's possible to have some stuff put in the registry on creation, but this is not really a use case. The Application should check if there are seetings and use the default settings if not.
第一:是的,这属于应用程序中您指定的确切原因:创建新用户配置文件后会发生什么?当然,如果您使用的是域,则可以在创建时将某些内容放入注册表,但这并不是真正的用例。应用程序应检查是否有设置,如果没有则使用默认设置。
That being said, it IS possible to change other users Keys through the HKEY_USERS Hive.
也就是说,可以通过 HKEY_USERS Hive 更改其他用户的密钥。
I have no experience with the Visual Studio 2003 Setup Project, so here is a bit of (totally unrelated) VBScript code that might just give you an idea where to look:
我没有使用 Visual Studio 2003 安装项目的经验,所以这里有一些(完全不相关的)VBScript 代码,它们可能只是让您知道在哪里查看:
const HKEY_USERS = &H80000003
strComputer = "."
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\" & strComputer & "\root\default:StdRegProv")
strKeyPath = ""
objReg.EnumKey HKEY_USERS, strKeyPath, arrSubKeys
strKeyPath = "\Software\Microsoft\Windows\CurrentVersion\WinTrust\Trust Providers\Software Publishing"
For Each subkey In arrSubKeys
objReg.SetDWORDValue HKEY_USERS, subkey & strKeyPath, "State", 146944
Next
(Code Courtesy of Jeroen Ritmeijer)
(代码由Jeroen Ritmeijer 提供)
回答by Orion Edwards
I'm guessing that because you want to set it for all users, that you're on some kind of shared computer, which is probably running under a domain?
我猜是因为你想为所有用户设置它,你在某种共享计算机上,它可能在域下运行?
HERE BE DRAGONS
这里是龙
Let's say Joe and Jane regularly log onto the computer, then they will each have 'registries'.
假设 Joe 和 Jane 定期登录计算机,那么他们将各自拥有“注册表”。
You'll then install your app, and the installer will employ giant hacks and disgusting things to set items under HKCU for them.
然后您将安装您的应用程序,安装程序将使用巨大的黑客和恶心的东西为它们设置 HKCU 下的项目。
THEN, bob will come along and log on (he, and 500 other people have accounts in the domain and so can do this). He's never used this computer before, so he has no registry. The first time he logs in, windows creates him one, but he won't have your setting.
然后,bob 会过来登录(他和其他 500 人在域中有帐户,因此可以这样做)。他以前从未使用过这台电脑,所以他没有注册表。他第一次登录时,Windows 会为他创建一个,但他不会拥有您的设置。
Your app then falls over or behaves incorrectly, and bob complains loudly about those crappy products from raynixon incorporated.
然后,您的应用程序发生故障或行为不正确,并且鲍勃大声抱怨 raynixon 公司的那些蹩脚产品。
The correct answer is to just have some default settings in your app, which can write them to the registry if it doesn't find them. It's general good practice that your app should never depend on the registry, and should create things as needed, for any registry entry, not just HKCU, anyway
正确的答案是在您的应用程序中只有一些默认设置,如果找不到它们,可以将它们写入注册表。你的应用程序永远不应该依赖于注册表,并且应该根据需要为任何注册表项创建东西,而不仅仅是 HKCU,这是一般的好习惯
回答by Ray
Despite what the MSDN articleArchive of MSDN Articlesays about User/Machine Hive, it doesn't write to HKEY_USERS. Rather it writes to HKCU if you select Just Me and HKLM if you select everyone.
尽管MSDN 文章Archive of MSDN 文章关于 User/Machine Hive有什么说法,但它并没有写入 HKEY_USERS。相反,如果您选择 Just Me,则它会写入 HKCU,如果您选择所有人,则它会写入 HKLM。
So my solution is going to be to use the User/Machine Hive, and then in the application it checks if the registry entries are in HKCU and if not, copies them from HKLM. I know this probably isn't the most ideal way of doing it, but it has the least amount of changes.
所以我的解决方案是使用用户/机器配置单元,然后在应用程序中检查注册表项是否在 HKCU 中,如果不是,则从 HKLM 复制它们。我知道这可能不是最理想的方式,但它的变化最少。
回答by Ray
I'm partway to my solution with this entry on MSDN (don't know how I couldn't find it before).
我正在通过 MSDN 上的这个条目解决我的解决方案(不知道我以前怎么找不到它)。
User/Machine Hive
Subkeys and values entered under this hive will be installed under the HKEY_CURRENT_USER hive when a user chooses "Just Me" or the HKEY_USERS hive or when a user chooses "Everyone" during installation.
当用户选择“Just Me”或 HKEY_USERS 配置单元或用户在安装过程中选择“Everyone”时,在此配置单元下输入的用户/机器配置单元子项和值将安装在 HKEY_CURRENT_USER 配置单元下。

