Need to run a script as a user

I need to run a script as a user to remove the new windows 10 “let’s finish setting up your device” after the 2004 update that only offer a “remind me in 3 days” button.

This is my script but when I run it form simplehelp toolbox it is running as Local System and the change are done to HKEY_USERS\S-1-5-18 instead of the current user.

Any tips to run this from the toolbox as the local user ?

set __COMPAT_LAYER=RunAsInvoker
REGEDIT.EXE /S c:\temp\engagementfix.reg
REGEDIT.EXE /S c:\temp\suggestedcontent.reg

content of the reg files :

suggestedcontent.reg
Windows Registry Editor Version 5.0

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager]
“SubscribedContent-338393Enabled”=dword:00000000
“SubscribedContent-353694Enabled”=dword:00000000
“SubscribedContent-353696Enabled”=dword:00000000
“SubscribedContent-310093Enabled”=dword:00000000

engagementfix.reg
Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\UserProfileEngagement]
“ScoobeSystemSettingEnabled”=dword:00000000

This can be tricky since SimpleHelp doesn’t do it out of the box (but I really hope it will at some point).

Two options I can think of:

  1. User PS to create a scheduled task that will then run as the currently logged in user: here
  2. Use PSExec in interactive mode, which should run via the console (i.e. the logged in user): here

I am working on a way…

If you use powershell you can get the current user that is logged in with

$logged_in_user = Get-WmiObject -Class Win32_ComputerSystem | Select-Object -ExpandProperty UserName
$currentUsername = $logged_in_user -replace ‘^.*\’

Then you can use that $currentUsername to search through the profilelist key of registry :slight_smile:

#Look in the ProfileList registry to find the corresponding SID
$profileListPath = “Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList”
$profiles = Get-ChildItem -Path $profileListPath

foreach ($profile in $profiles) {
$profileImagePath = (Get-ItemProperty -Path “registry::$profile”).ProfileImagePath

if ($profileImagePath -like “*$currentUsername”) {
# Extract the SID from the ProfileList registry key name
$userSID = $profile.Name.Split('')[-1]

then you can create a runonce key for the current user to run a .bat file to “merge a .reg file” when they log back on next…

#Construct the RunOnce key path for the user’s registry hive
$runOnceKeyPath = “Registry::HKEY_USERS$userSID\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce”

#Define the command you want to run as a RunOnce entry
$commandToRun = “C:\Location of file\Name of file.bat”

#Add the command to the RunOnce key of the user’s registry hive
New-Item -Path $runOnceKeyPath -Force
New-ItemProperty -Path $runOnceKeyPath -Name “TempRunOnceName” -PropertyType String -Value $commandToRun

Write-Host “RunOnce entry added for user SID: $userSID”
break
}

}

If that makes sense?

I got this working in another system we use to deploy scripts and etc… when script is running as “System” I am converting to SimpleHelp to test it there as well…

:slight_smile:

J

Specifying the user you want to run it has is a little more difficult, but if its just the current logged in user, that’s easy. Select currently logged in user from the drop down in the configuration of your toolbox.