Basic script to configure settings

Hi all,
Please forgive my naivety. I’m new to scripting.
I’m trying to configure a few things on a bunch of PC’s.
Two out of the three things work. But the first one, setting the right-click menu in W11 to be like the old classic one will not work no matter what we try. Batch, PS, System or logged in user. Running it on the PC directly, it does work.
Even separated out as single line item.
Any help would be very much welcomed.

Here is a copy of the script.

reg add “HKCU\Software\Classes\CLSID{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\InprocServer32” /f /ve

Supposed to set the Windows 11 right-click context menu back to how it was in Windows 10.
This works if run directly on the computer in the current user profile with an unelevated PS or CMD window.

Remove-LocalUser -Name “BASEIMG USER”
Works fine

POWERCFG -DUPLICATESCHEME 381b4222-f694-41f0-9685-ff5bb260df2e 381b4222-f694-41f0-9685-ff5bb260aaaa
POWERCFG -CHANGENAME 381b4222-f694-41f0-9685-ff5bb260aaaa “Titan”
POWERCFG -SETACTIVE 381b4222-f694-41f0-9685-ff5bb260aaaa
POWERCFG -Change -monitor-timeout-ac 30
POWERCFG -CHANGE -monitor-timeout-dc 30
POWERCFG -CHANGE -disk-timeout-ac 0
POWERCFG -CHANGE -disk-timeout-dc 0
POWERCFG -CHANGE -standby-timeout-ac 0
POWERCFG -CHANGE -standby-timeout-dc 0
POWERCFG -CHANGE -hibernate-timeout-ac 0
POWERCFG -CHANGE -hibernate-timeout-dc 0
Works fine

Your issue is the HKCU is Current User. So this needs to run in the logged in user context. When running scripts through any RMM, it’s done using the System permissions, so individual user context items will not work.

You need to either run the script as the logged in user, or mount that users reg hive and then modify the registry as needed, then unmount.

I actually load the hive for users that way they don’t need to be logged in and it can loop through and get all users on a machine if necessary when I am doing things like this.

Thank you so much for this information.
Do you know if there is a way to automate this procedure via another script?
I will have so many to do that are already out there installed, doing them manually will be a nightmare.
I’m very new to scripting of any kind, let alone via RMM.

Thank you again.

Sure, if you’re just trying to do it for the currently logged in user, just throw this in a script in Syncro and run it:

$LoggedInUser = ((Get-WMIObject -class Win32_ComputerSystem).UserName).Split("\")[1]
$USID = (Get-WmiObject Win32_UserAccount | Where-Object { $_.Name -eq $LoggedInUser }).SID

New-Item "Registry::\HKEY_USERS\$USID\Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\InprocServer32" -Force
Set-ItemProperty "Registry::\HKEY_USERS\$USID\Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\InprocServer32" -Name "(Default)" -Value ""

Can you please give an example? I have many scripts that run as logged in user, but fail because they are not logged in… This would be so helpful!

Sure. Here is one such script I wrote that allows you to set the Windows 11 taskbar alignment. Setup 2 runtime variables in Syncro, one for the specifying a single user if desired, otherwise leave it blank, the other a dropdown to select Left or Center alignment.

$UsersToModify = $SyncroUser

if ($Alignment -eq "Left") {
    $TaskbarAl = 0
else {
    $TaskbarAl = 1

if (!($UsersToModify)) {
    Write-Host "User input not provided. Getting list of all users..."
    $UsersToModify = (Get-ChildItem "$env:systemDrive\Users" | Where-Object { $_.Name -notmatch "Public|Administrator|Default" }).Name

foreach ($UTM in $UsersToModify) {

    $HivetoLoad = "$env:systemDrive\Users\$UTM\NTUSER.DAT"

    if (Test-Path $HivetoLoad) {
        Write-Host "Currently loading $($HivetoLoad)..."
        $LoadHive = REG LOAD HKU\tempload $HivetoLoad
        if ($LoadHive -match "successfully") {
            Write-Host "Hive loaded successfully, now setting registry entires..."
            $BaseRegPath = "Registry::\HKEY_USERS\tempload\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced"
            Set-ItemProperty $BaseRegPath -Name "TaskbarAl" -Value $TaskbarAl

            Clear-Variable BaseRegPath
            $UnloadHive = REG UNLOAD HKU\tempload
            if ($UnloadHive -match "successfully") {
                Write-Host "Registry entries modified. Hive unloaded."
            else {
                Write-Host "Failed to unload hive."
        else {
            Write-Host "Failed to load hive."
    else {
        Write-Host "NTUser.dat not found."

Write-Host "Finished looping through all selected users."
1 Like

That is great. Thanks!

If the answer to this question is yes, I will start a new thread: the above script works great for reg keys - is it possible to do something similar for software installations? I.e. can I install a program to a specific user or all users on a PC that no one is logged onto? Many of my software installs from an .msi or .exe are ran as the logged on user to set extra settings.

I’m going to start by saying if these machines are part of a domain, then you should be doing software installs like that via GPO when the user logs in. That’s the best and most consistent way.

However, if they are not part of a domain, the in theory you could script loading the hive as I do in my previous post, and modifying the HKU RunOnce reg key to kick off an install when they log in, but I can’t promise how consistent or well that would work.