Using Active Setup: How to Set a Registry Value in All User Hives

choubertsprojects

The Best WordPress plugins!

1. WP Reset

2. WP 301 Redirects

3. WP Force SSL

Active Setup is a feature of Windows that allows you to easily set registry values in all user profiles without the need for logon. It can be used not only when setting up clean installs but also during upgrades, reinstalls and other cleanup tasks. This walkthrough will show you how it’s done.

run batch file in active setup” is a command-line tool that allows users to set registry values in all user hives. The “run batch file in active setup” command needs to be run as an administrator.

Using Active Setup: How to Set a Registry Value in All User Hives

Having trouble figuring out how to change registry entries and values for all users on Windows? Don’t look any further! The registry and Active Setup are here to help!

Without Active Setup, the Battle

To deploy my apps, I’m continuously building PowerShell scripts. At least 1/4 of these apps need the addition or modification of registry values in both HKEY LOCAL MACHINE and HKEY CURRENT USER.

I dread every time I receive a batch file from an application owner that references HKEY CURRENT USER. I shudder because I need to change a registry setting for all users on the desktop, not just the presently logged on user, to guarantee that everyone who uses that system may use the program.

Because of two factors, it’s not as easy as changing a value in HKEY CURRENT USERSoftwareMyApplication.

  1. I deliver software to computers using the SYSTEM account on the local machine. When a person is logged in, the HKEY CURRENT USER “hive” is accessible. I don’t have access to the “actual” logged in user hive because I’m “logged on” as SYSTEM.
  2. Even if I could access to HKEY CURRENT USER, changing a registry setting isn’t enough. To guarantee that each user that logs into that computer has a consistent experience, it’s required to change a variable not only for the presently logged on user, but for all users on that system.

Don’t worry, there are answers, but first, a little primer on HKEY CURRENT USER. HKEY CURRENT USER is merely a reference to HKEY USERS percent USERSID percent, which is accessible by anybody other than the presently logged in user.

This implies I can simply edit a registry value under the user SID registry entry in HKEY USERS, which is the same as HKEY CURRENT USER, while executing a script as SYSTEM on a machine with an interactive login. For the currently logged in user, the issue has been resolved. Yay!

Changing the value for across all user profiles is the next step. This is when it becomes tough. For years, I used a VBscript to search through every user profile on the file system, load the user’s NTUser.dat file, make any necessary changes, and then unload it. It worked…on sometimes.

I discovered that every now and then, there would be permission issues of some type, leaving the hive in limbo. When the impacted person signed in again, their profile was corrupted, and rage ensued. I needed to find a better option.

How the Registry and Active Setup Work

This is why I began to use a function known as Active Setup. To understand more about the functionality, see the link, but in a word, it’s an easy way to execute a command once for each user (new or existing) on a computer.

When a user signs in, Active Setup checks to see whether a specific registry key in HKEY LOCAL MACHINE matches a key in the current HKEY CURRENT USER. If not, it runs a command supplied in the StubPath registry value. This is a great technique to implement the RunOnce function per-user for the whole system.

In my case, I’m using this approach to insert an old-school reg add command into HKEY CURRENT USER to create or alter a registry value. Because Active Setup always runs in the context of the currently logged on user, I now have the ability to perform anything I need at that time.

Scripting using PowerShell

You know I wouldn’t get you all excited about this wonderful method without also showing you how to do it in PowerShell, right? Here’s what I came up with to do this: a PowerShell function you can call from your script.

I kept things as simple as possible. You don’t have to worry about all the essential pathways with only one line. It just works everywhere. You’re done after providing a hashtable containing the registry key location, name, value, and the kind of registry value you’d want to create/modify. If you need to alter many values, just supply an array to it and it will do it.

https://github.com/Adam-the-Automator/Scripts/blob/main/Set-RegistryValueForAllUsers.ps1

How to Use the Get-ChildItem Cmdlet in PowerShell

Active Setup is a feature that allows users to set registry values for all users. This article will show you how to set a registry key for specific user. Reference: set registry key for specific user.

Related Tags

  • how to run active setup multiple times
  • add registry key to all users
  • disable active setup windows 10
  • active setup registry key download
  • powershell change current user registry

Table of Content