<p>I'm trying to maintain a Setup Project in <code>Visual Studio 2003</code> (yes, it's a legacy application). The problem we have at the moment is that we need to write registry entries to <code>HKCU</code> for every user on the computer. They need to be in the <code>HKCU</code> rather than <code>HKLM</code> because they are the default user settings, and they do change per user. My feeling is that</p>

<ol>
<li>This isn't possible</li>
<li>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?).</li>
</ol>

<p>With that in mind, I still want to change as little as possible in the application, so my question is, <strong>is it possible to add registry entries for every user in a <code>Visual Studio 2003</code> setup project?</strong> </p>

<p>And, at the moment the project lists five registry root keys (<code>HKEY_CLASSES_ROOT, HKEY_CURRENT_USER</code>, <code>HKEY_LOCAL_MACHINE</code>, <code>HKEY_USERS</code>, 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.</p>

[{'answer_id': 818, 'author': 'Ray', 'author_id': 233, 'author_profile': 'https://Stackoverflow.com/users/233', 'pm_score': 2, 'selected': False, 'text': '<p>I\'m partway to my solution with this entry on MSDN (don\'t know how I couldn\'t find it before).</p>\n\n<p>User/Machine Hive<br>\nSubkeys 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.</p>\n\n<p><s><a href="http://msdn.microsoft.com/en-us/library/x6kd89c5(VS.80).aspx" rel="nofollow noreferrer">Registry Editor</a></s> <a href="http://web.archive.org/web/20100112132447/http://msdn.microsoft.com/en-us/library/x6kd89c5(VS.80).aspx" rel="nofollow noreferrer">Archive of MSDN Article</a></p>\n'}, {'answer_id': 820, 'author': 'Michael Stum', 'author_id': 91, 'author_profile': 'https://Stackoverflow.com/users/91', 'pm_score': 4, 'selected': True, 'text': '<p>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.</p>\n\n<p>That being said, it IS possible to change other users Keys through the HKEY_USERS Hive.</p>\n\n<p>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:</p>\n\n<pre><code>const HKEY_USERS = &amp;H80000003\nstrComputer = "."\nSet objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\" &amp; strComputer &amp; "\\root\\default:StdRegProv")\nstrKeyPath = ""\nobjReg.EnumKey HKEY_USERS, strKeyPath, arrSubKeys\nstrKeyPath = "\\Software\\Microsoft\\Windows\\CurrentVersion\\WinTrust\\Trust Providers\\Software Publishing"\nFor Each subkey In arrSubKeys\n    objReg.SetDWORDValue HKEY_USERS, subkey &amp; strKeyPath, "State", 146944\nNext\n</code></pre>\n\n<p>(Code Courtesy of <a href="http://jritmeijer.spaces.live.com/blog/cns!8A48A27460FB898A!965.entry" rel="noreferrer">Jeroen Ritmeijer</a>)</p>\n'}, {'answer_id': 829, 'author': 'Orion Edwards', 'author_id': 234, 'author_profile': 'https://Stackoverflow.com/users/234', 'pm_score': 3, 'selected': False, 'text': "<p>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?</p>\n\n<p><strong>HERE BE DRAGONS</strong></p>\n\n<p>Let's say Joe and Jane regularly log onto the computer, then they will each have 'registries'.</p>\n\n<p>You'll then install your app, and the installer will employ giant hacks and disgusting things to set items under HKCU for them.</p>\n\n<p>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. </p>\n\n<p>Your app then falls over or behaves incorrectly, and bob complains loudly about those crappy products from raynixon incorporated.</p>\n\n<p>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</p>\n"}, {'answer_id': 870, 'author': 'Ray', 'author_id': 233, 'author_profile': 'https://Stackoverflow.com/users/233', 'pm_score': 2, 'selected': False, 'text': '<p>Despite what the <s><a href="http://msdn.microsoft.com/en-us/library/x6kd89c5(VS.80).aspx" rel="nofollow noreferrer">MSDN article</a></s> <a href="http://web.archive.org/web/20100112132447/http://msdn.microsoft.com/en-us/library/x6kd89c5(VS.80).aspx" rel="nofollow noreferrer">Archive of MSDN Article</a>  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.</p>\n\n<p>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.</p>\n'}]
['https://Stackoverflow.com/questions/810', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/233/']