Visual Studio安装项目 - 每用户注册表设置

时间:2023-01-16 15:39:02

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 HKCU for every user on the computer. They need to be in the HKCU rather than HKLM because they are the default user settings, and they do change per user. My feeling is that

我正在尝试在Visual Studio 2003中维护一个安装项目(是的,它是一个遗留应用程序)。我们目前遇到的问题是我们需要为计算机上的每个用户编写注册表项到HKCU。他们需要在HKCU而不是HKLM,因为他们是默认的用户设置,并且他们确实按用户更改。我的感觉就是这样

  1. This isn't possible
  2. 这是不可能的

  3. 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?).
  4. 这不是安装程序应该做的事情,而是应用程序应该做的事情(毕竟在安装后创建用户配置文件时会发生什么?)。

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 2003 setup 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和User / Machine Hive)。我对用户root密钥一无所知,也没有看过User / Machine Hive。任何人都可以告诉我他们是什么?也许他们可以解决我上面的问题。

4 个解决方案

#1


5  

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.

第一:是的,这是属于您指定的确切共振的应用程序中的内容:创建新用户配置文件后会发生什么?当然,如果你正在使用一个域,那么在创建时可能会在注册表中放入一些东西,但这不是一个真正的用例。应用程序应检查是否有seetings,如果没有,则使用默认设置。

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提供)

#2


5  

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.

然后,鲍勃会出现并登录(他和其他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。

#3


1  

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配置单元下。

Registry Editor

#4


1  

Despite what the MSDN article says 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文章中有关User / Machine Hive的内容,但它并没有写入HKEY_USERS。如果你选择所有人,如果你选择Just Me和HKLM,它会写入HKCU。

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.

所以我的解决方案是使用User / Machine Hive,然后在应用程序中检查注册表项是否在HKCU中,如果没有,则从HKLM复制它们。我知道这可能不是最理想的做法,但它的变化最少。

#1


5  

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.

第一:是的,这是属于您指定的确切共振的应用程序中的内容:创建新用户配置文件后会发生什么?当然,如果你正在使用一个域,那么在创建时可能会在注册表中放入一些东西,但这不是一个真正的用例。应用程序应检查是否有seetings,如果没有,则使用默认设置。

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提供)

#2


5  

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.

然后,鲍勃会出现并登录(他和其他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。

#3


1  

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配置单元下。

Registry Editor

#4


1  

Despite what the MSDN article says 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文章中有关User / Machine Hive的内容,但它并没有写入HKEY_USERS。如果你选择所有人,如果你选择Just Me和HKLM,它会写入HKCU。

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.

所以我的解决方案是使用User / Machine Hive,然后在应用程序中检查注册表项是否在HKCU中,如果没有,则从HKLM复制它们。我知道这可能不是最理想的做法,但它的变化最少。