views:

2800

answers:

4

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 do change per user. My feeling is that

  1. This isn't possible
  2. 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 possible to add registry entries for every user in a Visual Studio 2003 setup project?

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? Perhapes they could solve my problem above.

A: 

I'm partway to my solution with this entry on MSDN (don't know how I couldn't find it before).

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.

http://msdn.microsoft.com/en-us/library/x6kd89c5(VS.80).aspx

Ray
+3  A: 

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.

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:

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)

Michael Stum
+3  A: 

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'.

You'll then install your app, and the installer will employ giant hacks and disgusting things to set items under HKCU for them.

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.

Your app then falls over or behaves incorrectly, and bob complains loudly about those crappy products from raynixon incorporated.

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

Orion Edwards
A: 

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.

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.

Ray