diff options
| author | WindowsAddict <[email protected]> | 2024-09-26 20:43:21 +0530 |
|---|---|---|
| committer | WindowsAddict <[email protected]> | 2024-09-26 20:43:21 +0530 |
| commit | 841d856a29cee0444e10302de8650097ee69c161 (patch) | |
| tree | d68769734490dd0b83aeb5bb466388aaf337088b /MAS/Separate-Files-Version | |
| parent | 52d4c52dba8e29a3c1fb295c8946dbe6cf2f0239 (diff) | |
| download | Microsoft-Activation-Scripts-841d856a29cee0444e10302de8650097ee69c161.zip | |
Fix bugs in getting user accounts SID
Diffstat (limited to 'MAS/Separate-Files-Version')
| -rw-r--r-- | MAS/Separate-Files-Version/Activators/Ohook_Activation_AIO.cmd | 42 | ||||
| -rw-r--r-- | MAS/Separate-Files-Version/Activators/Online_KMS_Activation.cmd | 42 |
2 files changed, 50 insertions, 34 deletions
diff --git a/MAS/Separate-Files-Version/Activators/Ohook_Activation_AIO.cmd b/MAS/Separate-Files-Version/Activators/Ohook_Activation_AIO.cmd index ec2e8c9..b66bc40 100644 --- a/MAS/Separate-Files-Version/Activators/Ohook_Activation_AIO.cmd +++ b/MAS/Separate-Files-Version/Activators/Ohook_Activation_AIO.cmd @@ -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
diff --git a/MAS/Separate-Files-Version/Activators/Online_KMS_Activation.cmd b/MAS/Separate-Files-Version/Activators/Online_KMS_Activation.cmd index 306bb47..78f9a11 100644 --- a/MAS/Separate-Files-Version/Activators/Online_KMS_Activation.cmd +++ b/MAS/Separate-Files-Version/Activators/Online_KMS_Activation.cmd @@ -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
|
