1
0
Fork 0
mirror of https://github.com/massgravel/Microsoft-Activation-Scripts.git synced 2024-11-16 20:14:37 -05:00

Fix bugs in getting user accounts SID

This commit is contained in:
WindowsAddict 2024-09-26 20:43:21 +05:30
parent 52d4c52dba
commit 841d856a29
3 changed files with 76 additions and 51 deletions

View file

@ -2807,7 +2807,15 @@ set _sortIds=!_sortIds:PreInstallR_=Retail_!
:: https://learn.microsoft.com/office/troubleshoot/activation/reset-office-365-proplus-activation-state
set _sidlist=
for /f "tokens=* delims=" %%a in ('%psc% "$p = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList'; Get-ChildItem $p | ForEach-Object { $pi = (Get-ItemProperty """"$p\$($_.PSChildName)"""").ProfileImagePath; if ($pi -like """"$Env:SystemDrive\Users\*"""" -and (Test-Path """"$pi\NTUSER.DAT"""") -and -not ($_ -match '\.bak$')) { Split-Path $_.PSPath -Leaf } }" %nul6%') do (if defined _sidlist (set _sidlist=!_sidlist! %%a) else (set _sidlist=%%a))
set failedload=
for /f "tokens=* delims=" %%a in ('%psc% "$p = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList'; Get-ChildItem $p | ForEach-Object { $pi = (Get-ItemProperty """"$p\$($_.PSChildName)"""").ProfileImagePath; if ($_.PSChildName -match '^S-([^-\n]*-){5,}[^-\n]*$' -and (Test-Path """"$pi\NTUSER.DAT"""") -and -not ($_ -match '\.bak$')) { Split-Path $_.PSPath -Leaf } }" %nul6%') do (if defined _sidlist (set _sidlist=!_sidlist! %%a) else (set _sidlist=%%a))
:: Fallback method
if not defined _sidlist (
set failedload=1
for /f "delims=" %%a in ('%psc% "$explorerProc = Get-Process -Name explorer | Where-Object {$_.SessionId -eq (Get-Process -Id $pid).SessionId} | Select-Object -First 1; $sid = (gwmi -Query ('Select * From Win32_Process Where ProcessID=' + $explorerProc.Id)).GetOwnerSid().Sid; $sid" %nul6%') do (set _sidlist=%%a)
)
if not defined _sidlist (
set error=1
@ -2827,8 +2835,6 @@ call :dk_color %Gray% "Checking Total User Accounts [%counter%]"
:: Load the unloaded useraccounts registry
set loadedsids=
set failedtoload=
set failedtounload=
for %%# in (%_sidlist%) do (
reg query HKU\%%#\Software %nul% || (
for /f "skip=2 tokens=2*" %%a in ('"reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\%%#" /v ProfileImagePath" %nul6%') do (
@ -2836,7 +2842,7 @@ reg load HKU\%%# "%%b\NTUSER.DAT" %nul%
reg query HKU\%%#\Software %nul% && (
call set "loadedsids=%%loadedsids%% %%#"
) || (
set failedtoload=1
set failedload=1
)
)
)
@ -2898,13 +2904,19 @@ echo Clearing Office License Blocks [Successfully cleared from all %cou
:: Some retail products attempt to validate the license and may show a banner "There was a problem checking this device's license status."
:: Resiliency registry entry can skip this check
set faileddef=
for /f "skip=2 tokens=2*" %%a in ('"reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" /v Default" %nul6%') do call set "defdat=%%b"
if defined o16c2r if defined officeact (
reg load HKU\DEF_TEMP %SystemDrive%\Users\Default\NTUSER.DAT %nul%
reg query HKU\DEF_TEMP %nul% || set failedtoload=1
if exist "%defdat%\NTUSER.DAT" (
reg load HKU\DEF_TEMP "%defdat%\NTUSER.DAT" %nul%
reg query HKU\DEF_TEMP %nul% || set faileddef=1
reg add HKU\DEF_TEMP\Software\Microsoft\Office\16.0\Common\Licensing\Resiliency /v "TimeOfLastHeartbeatFailure" /t REG_SZ /d "2040-01-01T00:00:00Z" /f %nul%
reg unload HKU\DEF_TEMP %nul%
reg query HKU\DEF_TEMP %nul% && set failedtounload=1
reg query HKU\DEF_TEMP %nul% && set faileddef=1
) else (
set faileddef=1
)
for %%# in (%_sidlist%) do (
reg delete HKU\%%#\Software\Microsoft\Office\16.0\Common\Licensing\Resiliency /f %nul%
reg add HKU\%%#\Software\Microsoft\Office\16.0\Common\Licensing\Resiliency /v "TimeOfLastHeartbeatFailure" /t REG_SZ /d "2040-01-01T00:00:00Z" /f %nul%
@ -2918,19 +2930,15 @@ echo Adding Reg Keys to Skip License Check [Successfully added to all %counter
for %%# in (%loadedsids%) do (
reg unload HKU\%%# %nul%
reg query HKU\%%# %nul% && set failedtounload=1
reg query HKU\%%# %nul% && set failedload=1
)
if defined failedtoload (
set error=1
call :dk_color %Red% "Loading Unloaded Accounts Registry [Failed for some user accounts]"
call :dk_color %Blue% "Reboot your machine using the restart option and try again."
if defined failedload (
call :dk_color %Gray% "Loading Unloading Registries [Failed for some user accounts]"
)
if defined failedtounload (
set error=1
call :dk_color %Red% "Unloading Loaded Account Registries [Failed for some user accounts]"
call :dk_color %Blue% "Reboot your machine using the restart option and try again."
if defined faileddef (
call :dk_color %Gray% "Loading Unloading Registries [Failed for Default\NTUSER.DAT]"
)
exit /b
@ -10252,4 +10260,5 @@ if ($appIdsList.Count -gt 0) {
:getappnames:
::========================================================================================================================================
::
:: Leave empty line below

View file

@ -1106,7 +1106,15 @@ set _sortIds=!_sortIds:PreInstallR_=Retail_!
:: https://learn.microsoft.com/office/troubleshoot/activation/reset-office-365-proplus-activation-state
set _sidlist=
for /f "tokens=* delims=" %%a in ('%psc% "$p = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList'; Get-ChildItem $p | ForEach-Object { $pi = (Get-ItemProperty """"$p\$($_.PSChildName)"""").ProfileImagePath; if ($pi -like """"$Env:SystemDrive\Users\*"""" -and (Test-Path """"$pi\NTUSER.DAT"""") -and -not ($_ -match '\.bak$')) { Split-Path $_.PSPath -Leaf } }" %nul6%') do (if defined _sidlist (set _sidlist=!_sidlist! %%a) else (set _sidlist=%%a))
set failedload=
for /f "tokens=* delims=" %%a in ('%psc% "$p = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList'; Get-ChildItem $p | ForEach-Object { $pi = (Get-ItemProperty """"$p\$($_.PSChildName)"""").ProfileImagePath; if ($_.PSChildName -match '^S-([^-\n]*-){5,}[^-\n]*$' -and (Test-Path """"$pi\NTUSER.DAT"""") -and -not ($_ -match '\.bak$')) { Split-Path $_.PSPath -Leaf } }" %nul6%') do (if defined _sidlist (set _sidlist=!_sidlist! %%a) else (set _sidlist=%%a))
:: Fallback method
if not defined _sidlist (
set failedload=1
for /f "delims=" %%a in ('%psc% "$explorerProc = Get-Process -Name explorer | Where-Object {$_.SessionId -eq (Get-Process -Id $pid).SessionId} | Select-Object -First 1; $sid = (gwmi -Query ('Select * From Win32_Process Where ProcessID=' + $explorerProc.Id)).GetOwnerSid().Sid; $sid" %nul6%') do (set _sidlist=%%a)
)
if not defined _sidlist (
set error=1
@ -1126,8 +1134,6 @@ call :dk_color %Gray% "Checking Total User Accounts [%counter%]"
:: Load the unloaded useraccounts registry
set loadedsids=
set failedtoload=
set failedtounload=
for %%# in (%_sidlist%) do (
reg query HKU\%%#\Software %nul% || (
for /f "skip=2 tokens=2*" %%a in ('"reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\%%#" /v ProfileImagePath" %nul6%') do (
@ -1135,7 +1141,7 @@ reg load HKU\%%# "%%b\NTUSER.DAT" %nul%
reg query HKU\%%#\Software %nul% && (
call set "loadedsids=%%loadedsids%% %%#"
) || (
set failedtoload=1
set failedload=1
)
)
)
@ -1197,13 +1203,19 @@ echo Clearing Office License Blocks [Successfully cleared from all %cou
:: Some retail products attempt to validate the license and may show a banner "There was a problem checking this device's license status."
:: Resiliency registry entry can skip this check
set faileddef=
for /f "skip=2 tokens=2*" %%a in ('"reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" /v Default" %nul6%') do call set "defdat=%%b"
if defined o16c2r if defined officeact (
reg load HKU\DEF_TEMP %SystemDrive%\Users\Default\NTUSER.DAT %nul%
reg query HKU\DEF_TEMP %nul% || set failedtoload=1
if exist "%defdat%\NTUSER.DAT" (
reg load HKU\DEF_TEMP "%defdat%\NTUSER.DAT" %nul%
reg query HKU\DEF_TEMP %nul% || set faileddef=1
reg add HKU\DEF_TEMP\Software\Microsoft\Office\16.0\Common\Licensing\Resiliency /v "TimeOfLastHeartbeatFailure" /t REG_SZ /d "2040-01-01T00:00:00Z" /f %nul%
reg unload HKU\DEF_TEMP %nul%
reg query HKU\DEF_TEMP %nul% && set failedtounload=1
reg query HKU\DEF_TEMP %nul% && set faileddef=1
) else (
set faileddef=1
)
for %%# in (%_sidlist%) do (
reg delete HKU\%%#\Software\Microsoft\Office\16.0\Common\Licensing\Resiliency /f %nul%
reg add HKU\%%#\Software\Microsoft\Office\16.0\Common\Licensing\Resiliency /v "TimeOfLastHeartbeatFailure" /t REG_SZ /d "2040-01-01T00:00:00Z" /f %nul%
@ -1217,19 +1229,15 @@ echo Adding Reg Keys to Skip License Check [Successfully added to all %counter
for %%# in (%loadedsids%) do (
reg unload HKU\%%# %nul%
reg query HKU\%%# %nul% && set failedtounload=1
reg query HKU\%%# %nul% && set failedload=1
)
if defined failedtoload (
set error=1
call :dk_color %Red% "Loading Unloaded Accounts Registry [Failed for some user accounts]"
call :dk_color %Blue% "Reboot your machine using the restart option and try again."
if defined failedload (
call :dk_color %Gray% "Loading Unloading Registries [Failed for some user accounts]"
)
if defined failedtounload (
set error=1
call :dk_color %Red% "Unloading Loaded Account Registries [Failed for some user accounts]"
call :dk_color %Blue% "Reboot your machine using the restart option and try again."
if defined faileddef (
call :dk_color %Gray% "Loading Unloading Registries [Failed for Default\NTUSER.DAT]"
)
exit /b

View file

@ -1207,7 +1207,15 @@ exit /b
:: https://learn.microsoft.com/office/troubleshoot/activation/reset-office-365-proplus-activation-state
set _sidlist=
for /f "tokens=* delims=" %%a in ('%psc% "$p = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList'; Get-ChildItem $p | ForEach-Object { $pi = (Get-ItemProperty """"$p\$($_.PSChildName)"""").ProfileImagePath; if ($pi -like """"$Env:SystemDrive\Users\*"""" -and (Test-Path """"$pi\NTUSER.DAT"""") -and -not ($_ -match '\.bak$')) { Split-Path $_.PSPath -Leaf } }" %nul6%') do (if defined _sidlist (set _sidlist=!_sidlist! %%a) else (set _sidlist=%%a))
set failedload=
for /f "tokens=* delims=" %%a in ('%psc% "$p = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList'; Get-ChildItem $p | ForEach-Object { $pi = (Get-ItemProperty """"$p\$($_.PSChildName)"""").ProfileImagePath; if ($_.PSChildName -match '^S-([^-\n]*-){5,}[^-\n]*$' -and (Test-Path """"$pi\NTUSER.DAT"""") -and -not ($_ -match '\.bak$')) { Split-Path $_.PSPath -Leaf } }" %nul6%') do (if defined _sidlist (set _sidlist=!_sidlist! %%a) else (set _sidlist=%%a))
:: Fallback method
if not defined _sidlist (
set failedload=1
for /f "delims=" %%a in ('%psc% "$explorerProc = Get-Process -Name explorer | Where-Object {$_.SessionId -eq (Get-Process -Id $pid).SessionId} | Select-Object -First 1; $sid = (gwmi -Query ('Select * From Win32_Process Where ProcessID=' + $explorerProc.Id)).GetOwnerSid().Sid; $sid" %nul6%') do (set _sidlist=%%a)
)
if not defined _sidlist (
set error=1
@ -1227,8 +1235,6 @@ call :dk_color %Gray% "Checking Total User Accounts [%counter%]"
:: Load the unloaded useraccounts registry
set loadedsids=
set failedtoload=
set failedtounload=
for %%# in (%_sidlist%) do (
reg query HKU\%%#\Software %nul% || (
for /f "skip=2 tokens=2*" %%a in ('"reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\%%#" /v ProfileImagePath" %nul6%') do (
@ -1236,7 +1242,7 @@ reg load HKU\%%# "%%b\NTUSER.DAT" %nul%
reg query HKU\%%#\Software %nul% && (
call set "loadedsids=%%loadedsids%% %%#"
) || (
set failedtoload=1
set failedload=1
)
)
)
@ -1298,13 +1304,19 @@ echo Clearing Office License Blocks [Successfully cleared from all %cou
:: Some retail products attempt to validate the license and may show a banner "There was a problem checking this device's license status."
:: Resiliency registry entry can skip this check
set faileddef=
for /f "skip=2 tokens=2*" %%a in ('"reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" /v Default" %nul6%') do call set "defdat=%%b"
if defined o16c2r if defined officeact (
reg load HKU\DEF_TEMP %SystemDrive%\Users\Default\NTUSER.DAT %nul%
reg query HKU\DEF_TEMP %nul% || set failedtoload=1
if exist "%defdat%\NTUSER.DAT" (
reg load HKU\DEF_TEMP "%defdat%\NTUSER.DAT" %nul%
reg query HKU\DEF_TEMP %nul% || set faileddef=1
reg add HKU\DEF_TEMP\Software\Microsoft\Office\16.0\Common\Licensing\Resiliency /v "TimeOfLastHeartbeatFailure" /t REG_SZ /d "2040-01-01T00:00:00Z" /f %nul%
reg unload HKU\DEF_TEMP %nul%
reg query HKU\DEF_TEMP %nul% && set failedtounload=1
reg query HKU\DEF_TEMP %nul% && set faileddef=1
) else (
set faileddef=1
)
for %%# in (%_sidlist%) do (
reg delete HKU\%%#\Software\Microsoft\Office\16.0\Common\Licensing\Resiliency /f %nul%
reg add HKU\%%#\Software\Microsoft\Office\16.0\Common\Licensing\Resiliency /v "TimeOfLastHeartbeatFailure" /t REG_SZ /d "2040-01-01T00:00:00Z" /f %nul%
@ -1318,19 +1330,15 @@ echo Adding Reg Keys to Skip License Check [Successfully added to all %counter
for %%# in (%loadedsids%) do (
reg unload HKU\%%# %nul%
reg query HKU\%%# %nul% && set failedtounload=1
reg query HKU\%%# %nul% && set failedload=1
)
if defined failedtoload (
set error=1
call :dk_color %Red% "Loading Unloaded Accounts Registry [Failed for some user accounts]"
call :dk_color %Blue% "Reboot your machine using the restart option and try again."
if defined failedload (
call :dk_color %Gray% "Loading Unloading Registries [Failed for some user accounts]"
)
if defined failedtounload (
set error=1
call :dk_color %Red% "Unloading Loaded Account Registries [Failed for some user accounts]"
call :dk_color %Blue% "Reboot your machine using the restart option and try again."
if defined faileddef (
call :dk_color %Gray% "Loading Unloading Registries [Failed for Default\NTUSER.DAT]"
)
exit /b