I'm trying to save every sid under:


to some directory and I'm trying to control every logon my backup SID's exist or not under profilelist. if it's not than I must import my saved profiles.

I tried with batch script which I wrote, but my script doing this when an user login and it isn't good way to do this!

I am sharing it for you to understand what I want to do.

(script 1 must run with the user account without admin privileges.)

@echo on
IF EXIST D:\Users\ (goto dvar) else goto quit 
echo dvar
setlocal enabledelayedexpansion
echo %username%>D:\Users\username.txt
for /f "tokens=2 delims= " %%i in ('whoami /user /fo table /nh') do set usersid=%%i
echo %usersid%>>D:\Users\username.txt
echo %userprofile%>>D:\Users\username.txt
IF EXIST D:\Users\%username% (goto GetUserinf) else goto quit 

for /f "tokens=1 delims=." %%a in ('echo %userprofile%') do set newpath=%%a
IF %newpath%==%userprofile% (goto quit) else goto run



(script 2 must run with admin privileges.)

@echo on

set /p user=
set /p usersid=
set /p oldpath=

for /f "tokens=1 delims=." %%a in ('echo %oldpath%') do set newpath=%%a
echo OLD path %oldpath%  ---  NEW path=%newpath%

IF EXIST %newpath% (goto oldexist) else goto quit

set /P c=For continue "Y", For quit "N" [Y/N]?
if /I "%c%" EQU "Y" goto :reboot
if /I "%c%" EQU "N" goto :quit

reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\%usersid%" /v "ProfileImagePath" /t REG_EXPAND_SZ /d "%newpath%" /f
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce" /v "deleteprofile" /t REG_SZ /d "C:\Windows\system32\cmd.exe /q /c rmdir /s /q %oldpath%"

echo Windows Rebooting.
::shutdown -r -t 0


I found a Shell Script but i dont know shell VBS. I think with shell scripting this is really easy job.

Can you help me please? I stuck so hard...

$objUser = New-Object System.Security.Principal.NTAccount(Read-Host -Prompt "Enter Username")
$strSID = $objUser.Translate([System.Security.Principal.SecurityIdentifier])
Rename-Item -Path "HKLM:\Software\Microsoft\Windows NT\CurrentVersion\ProfileList\$($strSID.Value)" -NewName "$($strSID.Value).old"

You do not need all of them.
All you need is to do the following;

1- Reg export to some directory ".bat"
2- Reg import from there ".bat"
And time schedule for your 2 batch. "Import every startup" and "Export every logon".
Thats it, cheers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.