From 9f85d0a0f4da0a7383b8c60f366c9c9e4cf7d1d7 Mon Sep 17 00:00:00 2001 From: Xyueta Date: Tue, 19 Sep 2023 17:34:07 +0200 Subject: [PATCH] fix: spaces --- .../AtlasModules/Scripts/online-sxs.cmd | 274 +++++++++--------- src/playbook/Executables/ONED.cmd | 94 +++--- src/playbook/Executables/STARTMENU.cmd | 44 +-- 3 files changed, 206 insertions(+), 206 deletions(-) diff --git a/src/playbook/Executables/AtlasModules/Scripts/online-sxs.cmd b/src/playbook/Executables/AtlasModules/Scripts/online-sxs.cmd index 5228d1a795..6cdc16b40c 100644 --- a/src/playbook/Executables/AtlasModules/Scripts/online-sxs.cmd +++ b/src/playbook/Executables/AtlasModules/Scripts/online-sxs.cmd @@ -1,138 +1,138 @@ -<# : batch portion -@echo off -:: GPL-3.0-only license -:: he3als 2023 -:: https://github.com/he3als/online-sxs - -if "%~1"=="-Help" (goto help) else (if "%~1"=="-help" (goto help) else (if "%~1"=="/h" (goto help) else (goto main))) - -:help -echo Usage = online-sxs.cmd [-Help] [[-Silent] -CabPath ""] -exit /b - -:main -fltmc >nul 2>&1 || ( - echo Administrator privileges are required. - if "%*"=="" ( - PowerShell Start -Verb RunAs '%0' 2> nul || goto error - ) else ( - PowerShell Start -Verb RunAs '%0' -ArgumentList '%*' 2> nul || goto error - ) - exit /b 0 -) - -set args= & set "args1=%*" -if defined args1 set "args=%args1:"='%" -powershell -nop "& ([Scriptblock]::Create((Get-Content '%~f0' -Raw))) %args%" -exit /b %errorlevel% - -:error -echo You must run this script as admin. -pause & exit /b 1 - -: end batch / begin PowerShell #> - -param ( - [string]$CabPaths, - [switch]$Silent -) - -# You can automate this script with variables as well: -# $CabPaths = "$env:SystemDrive\Package.cab" -# Note: only works if $cabPath is defined -# $Silent = $true - -if ($CabPaths) { - $cabArg = $true - - if (!(Test-Path $CabPaths -PathType Leaf)) { - Write-Host "The specified files do not exist or aren't files." -ForegroundColor Red - exit 1 - } - - if (!((Get-Item $CabPaths).Extension -eq '.cab')) { - Write-Host "The specified files are not .cab files." -ForegroundColor Red - exit 1 - } -} else {$Silent = $false} - -$certRegPath = "HKLM:\SOFTWARE\Microsoft\SystemCertificates\ROOT\Certificates" - -function PauseNul ($message = "Press any key to exit... ") { - Write-Host $message -NoNewLine - $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown') | Out-Null -} - -if ($silent) {$ProgressPreference = 'SilentlyContinue'} - -if (!($cabArg)) { - Write-Host "This will install a specified CBS package online, meaning live on your current install of Windows." -ForegroundColor Yellow - Start-Sleep 1 - PauseNul "Press any key to continue... " - Write-Host "`n" - - Write-Warning "Opening file dialog to select CBS package CAB..." - Add-Type -AssemblyName System.Windows.Forms - $openFileDialog = New-Object System.Windows.Forms.OpenFileDialog - $openFileDialog.Multiselect = $true - $openFileDialog.Filter = "CBS Package Files (*.cab)|*.cab" - $openFileDialog.Title = "Select a CBS Package File" - if ($openFileDialog.ShowDialog() -eq 'OK') { - Clear-Host - } else {exit} -} - -function ProcessCab($cabPath) { - try { - if (!($Silent)) { - $filePath = Split-Path $cabPath -Leaf - if ($global:notFirstCab) {Write-Host ""} - Write-Host "Installing $filePath..." -ForegroundColor Green - Write-Host "----------------------------------------------------------------------------------------" -ForegroundColor Blue - $global:notFirstCab = $true - } - - if (!($silent)) {Write-Warning "Importing and checking certificate..."} - try { - $cert = (Get-AuthenticodeSignature $cabPath).SignerCertificate - foreach ($usage in $cert.Extensions.EnhancedKeyUsages) { if ($usage.Value -eq "1.3.6.1.4.1.311.10.3.6") { $correctUsage = $true } } - if (!($correctUsage)) { - Write-Host 'The certificate inside of the CAB selected does not have the "Windows System Component Verification" enhanced key usage.' -ForegroundColor Red - if (!($cabArg)) {PauseNul}; exit 1 - } - $certPath = [System.IO.Path]::GetTempFileName() - [System.IO.File]::WriteAllBytes($certPath, $cert.Export([System.Security.Cryptography.X509Certificates.X509ContentType]::Cert)) - Import-Certificate $certPath -CertStoreLocation "Cert:\LocalMachine\Root" | Out-Null - Copy-Item -Path "$certRegPath\$($cert.Thumbprint)" "$certRegPath\8A334AA8052DD244A647306A76B8178FA215F344" -Force | Out-Null - } catch { - Write-Host "`nSomething went wrong importing and checking the certificate of: $cabPath" -ForegroundColor Red - Write-Host "$_`n" -ForegroundColor Red - if (!($cabArg)) {PauseNul}; exit 1 - } - - if (!($silent)) {Write-Warning "Adding package..."} - try { - Add-WindowsPackage -Online -PackagePath $cabPath -NoRestart -IgnoreCheck -LogLevel 1 *>$null - } catch { - Write-Host "Something went wrong adding the package: $cabPath" -ForegroundColor Red - Write-Host "$_`n" -ForegroundColor Red - if (!($cabArg)) {PauseNul}; exit 1 - } - } finally { - if (!($silent)) {Write-Warning "Cleaning up certificates..."} - Get-ChildItem "Cert:\LocalMachine\Root\$($cert.Thumbprint)" | Remove-Item -Force | Out-Null - Remove-Item "$certRegPath\8A334AA8052DD244A647306A76B8178FA215F344" -Force -Recurse | Out-Null - } -} - -if ($cabArg) { - foreach ($cabPath in $CabPaths) {ProcessCab $cabPath} -} else { - foreach ($cabPath in $openFileDialog.FileNames) {ProcessCab $cabPath} -} - -if (!($silent)) {Write-Host "`nCompleted!" -ForegroundColor Green} -if (!($cabArg)) { - choice /c yn /n /m "Would you like to restart now to apply the changes? [Y/N] " - if ($lastexitcode -eq 1) {Restart-Computer} +<# : batch portion +@echo off +:: GPL-3.0-only license +:: he3als 2023 +:: https://github.com/he3als/online-sxs + +if "%~1"=="-Help" (goto help) else (if "%~1"=="-help" (goto help) else (if "%~1"=="/h" (goto help) else (goto main))) + +:help +echo Usage = online-sxs.cmd [-Help] [[-Silent] -CabPath ""] +exit /b + +:main +fltmc >nul 2>&1 || ( + echo Administrator privileges are required. + if "%*"=="" ( + PowerShell Start -Verb RunAs '%0' 2> nul || goto error + ) else ( + PowerShell Start -Verb RunAs '%0' -ArgumentList '%*' 2> nul || goto error + ) + exit /b 0 +) + +set args= & set "args1=%*" +if defined args1 set "args=%args1:"='%" +powershell -nop "& ([Scriptblock]::Create((Get-Content '%~f0' -Raw))) %args%" +exit /b %errorlevel% + +:error +echo You must run this script as admin. +pause & exit /b 1 + +: end batch / begin PowerShell #> + +param ( + [string]$CabPaths, + [switch]$Silent +) + +# You can automate this script with variables as well: +# $CabPaths = "$env:SystemDrive\Package.cab" +# Note: only works if $cabPath is defined +# $Silent = $true + +if ($CabPaths) { + $cabArg = $true + + if (!(Test-Path $CabPaths -PathType Leaf)) { + Write-Host "The specified files do not exist or aren't files." -ForegroundColor Red + exit 1 + } + + if (!((Get-Item $CabPaths).Extension -eq '.cab')) { + Write-Host "The specified files are not .cab files." -ForegroundColor Red + exit 1 + } +} else {$Silent = $false} + +$certRegPath = "HKLM:\SOFTWARE\Microsoft\SystemCertificates\ROOT\Certificates" + +function PauseNul ($message = "Press any key to exit... ") { + Write-Host $message -NoNewLine + $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown') | Out-Null +} + +if ($silent) {$ProgressPreference = 'SilentlyContinue'} + +if (!($cabArg)) { + Write-Host "This will install a specified CBS package online, meaning live on your current install of Windows." -ForegroundColor Yellow + Start-Sleep 1 + PauseNul "Press any key to continue... " + Write-Host "`n" + + Write-Warning "Opening file dialog to select CBS package CAB..." + Add-Type -AssemblyName System.Windows.Forms + $openFileDialog = New-Object System.Windows.Forms.OpenFileDialog + $openFileDialog.Multiselect = $true + $openFileDialog.Filter = "CBS Package Files (*.cab)|*.cab" + $openFileDialog.Title = "Select a CBS Package File" + if ($openFileDialog.ShowDialog() -eq 'OK') { + Clear-Host + } else {exit} +} + +function ProcessCab($cabPath) { + try { + if (!($Silent)) { + $filePath = Split-Path $cabPath -Leaf + if ($global:notFirstCab) {Write-Host ""} + Write-Host "Installing $filePath..." -ForegroundColor Green + Write-Host "----------------------------------------------------------------------------------------" -ForegroundColor Blue + $global:notFirstCab = $true + } + + if (!($silent)) {Write-Warning "Importing and checking certificate..."} + try { + $cert = (Get-AuthenticodeSignature $cabPath).SignerCertificate + foreach ($usage in $cert.Extensions.EnhancedKeyUsages) { if ($usage.Value -eq "1.3.6.1.4.1.311.10.3.6") { $correctUsage = $true } } + if (!($correctUsage)) { + Write-Host 'The certificate inside of the CAB selected does not have the "Windows System Component Verification" enhanced key usage.' -ForegroundColor Red + if (!($cabArg)) {PauseNul}; exit 1 + } + $certPath = [System.IO.Path]::GetTempFileName() + [System.IO.File]::WriteAllBytes($certPath, $cert.Export([System.Security.Cryptography.X509Certificates.X509ContentType]::Cert)) + Import-Certificate $certPath -CertStoreLocation "Cert:\LocalMachine\Root" | Out-Null + Copy-Item -Path "$certRegPath\$($cert.Thumbprint)" "$certRegPath\8A334AA8052DD244A647306A76B8178FA215F344" -Force | Out-Null + } catch { + Write-Host "`nSomething went wrong importing and checking the certificate of: $cabPath" -ForegroundColor Red + Write-Host "$_`n" -ForegroundColor Red + if (!($cabArg)) {PauseNul}; exit 1 + } + + if (!($silent)) {Write-Warning "Adding package..."} + try { + Add-WindowsPackage -Online -PackagePath $cabPath -NoRestart -IgnoreCheck -LogLevel 1 *>$null + } catch { + Write-Host "Something went wrong adding the package: $cabPath" -ForegroundColor Red + Write-Host "$_`n" -ForegroundColor Red + if (!($cabArg)) {PauseNul}; exit 1 + } + } finally { + if (!($silent)) {Write-Warning "Cleaning up certificates..."} + Get-ChildItem "Cert:\LocalMachine\Root\$($cert.Thumbprint)" | Remove-Item -Force | Out-Null + Remove-Item "$certRegPath\8A334AA8052DD244A647306A76B8178FA215F344" -Force -Recurse | Out-Null + } +} + +if ($cabArg) { + foreach ($cabPath in $CabPaths) {ProcessCab $cabPath} +} else { + foreach ($cabPath in $openFileDialog.FileNames) {ProcessCab $cabPath} +} + +if (!($silent)) {Write-Host "`nCompleted!" -ForegroundColor Green} +if (!($cabArg)) { + choice /c yn /n /m "Would you like to restart now to apply the changes? [Y/N] " + if ($lastexitcode -eq 1) {Restart-Computer} } \ No newline at end of file diff --git a/src/playbook/Executables/ONED.cmd b/src/playbook/Executables/ONED.cmd index b0c0ea148f..4be52b42d9 100644 --- a/src/playbook/Executables/ONED.cmd +++ b/src/playbook/Executables/ONED.cmd @@ -1,48 +1,48 @@ -@echo off -setlocal EnableDelayedExpansion - -taskkill /f /im OneDrive*.exe > nul 2>&1 -"%windir%\System32\OneDriveSetup.exe" /uninstall -"%windir%\SysWOW64\OneDriveSetup.exe" /uninstall - -:: If the "Volatile Environment" key exists, that means it is a proper user. Built in accounts/SIDs don't have this key. -for /f "usebackq tokens=2 delims=\" %%a in (`reg query HKU ^| findstr /r /x /c:"HKEY_USERS\\S-.*" /c:"HKEY_USERS\\AME_UserHive_[^_]*"`) do ( - reg query "HKU\%%a" | findstr /c:"Volatile Environment" /c:"AME_UserHive_" > nul && ( - echo Making changes for "%%a"... - call :USERREG "%%a" - ) -) - -rmdir /q /s "%ProgramData%\Microsoft OneDrive" > nul 2>&1 -rmdir /q /s "%LOCALAPPDATA%\Microsoft\OneDrive" > nul 2>&1 - -for /f "usebackq delims=" %%a in (`dir /b /a:d "%SystemDrive%\Users"`) do ( - rmdir /q /s "%SystemDrive%\Users\%%a\AppData\Local\Microsoft\OneDrive" > nul 2>&1 - rmdir /q /s "%SystemDrive%\Users\%%a\OneDrive" > nul 2>&1 - del /q /f "%SystemDrive%\Users\%%a\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\OneDrive.lnk" > nul 2>&1 -) - -for /f "usebackq delims=" %%a in (`reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\SyncRootManager" ^| findstr /i /c:"OneDrive"`) do reg delete "%%a" /f > nul 2>&1 - -for /f "tokens=2 delims=\" %%a in ('schtasks /query /fo list /v ^| findstr /c:"\OneDrive Reporting Task" /c:"\OneDrive Standalone Update Task"') do ( - schtasks /delete /tn "%%a" /f > nul 2>&1 -) - -exit /b - -:USERREG -for /f "usebackq delims=" %%a in (`reg query "HKU\%~1\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\BannerStore" ^| findstr /i /c:"OneDrive"`) do ( - reg delete "%%a" /f > nul 2>&1 -) -for /f "usebackq delims=" %%a in (`reg query "HKU\%~1\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\AutoplayHandlers\Handlers" ^| findstr /i /c:"OneDrive"`) do ( - reg delete "%%a" /f > nul 2>&1 -) -for /f "usebackq delims=" %%a in (`reg query "HKU\%~1\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths" ^| findstr /i /c:"OneDrive"`) do ( - reg delete "%%a" /f > nul 2>&1 -) -for /f "usebackq delims=" %%a in (`reg query "HKU\%~1\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" ^| findstr /i /c:"OneDrive"`) do ( - reg delete "%%a" /f > nul 2>&1 -) - -reg delete "HKU\%~1\Environment" /v "OneDrive" /f > nul 2>&1 +@echo off +setlocal EnableDelayedExpansion + +taskkill /f /im OneDrive*.exe > nul 2>&1 +"%windir%\System32\OneDriveSetup.exe" /uninstall +"%windir%\SysWOW64\OneDriveSetup.exe" /uninstall + +:: If the "Volatile Environment" key exists, that means it is a proper user. Built in accounts/SIDs don't have this key. +for /f "usebackq tokens=2 delims=\" %%a in (`reg query HKU ^| findstr /r /x /c:"HKEY_USERS\\S-.*" /c:"HKEY_USERS\\AME_UserHive_[^_]*"`) do ( + reg query "HKU\%%a" | findstr /c:"Volatile Environment" /c:"AME_UserHive_" > nul && ( + echo Making changes for "%%a"... + call :USERREG "%%a" + ) +) + +rmdir /q /s "%ProgramData%\Microsoft OneDrive" > nul 2>&1 +rmdir /q /s "%LOCALAPPDATA%\Microsoft\OneDrive" > nul 2>&1 + +for /f "usebackq delims=" %%a in (`dir /b /a:d "%SystemDrive%\Users"`) do ( + rmdir /q /s "%SystemDrive%\Users\%%a\AppData\Local\Microsoft\OneDrive" > nul 2>&1 + rmdir /q /s "%SystemDrive%\Users\%%a\OneDrive" > nul 2>&1 + del /q /f "%SystemDrive%\Users\%%a\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\OneDrive.lnk" > nul 2>&1 +) + +for /f "usebackq delims=" %%a in (`reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\SyncRootManager" ^| findstr /i /c:"OneDrive"`) do reg delete "%%a" /f > nul 2>&1 + +for /f "tokens=2 delims=\" %%a in ('schtasks /query /fo list /v ^| findstr /c:"\OneDrive Reporting Task" /c:"\OneDrive Standalone Update Task"') do ( + schtasks /delete /tn "%%a" /f > nul 2>&1 +) + +exit /b + +:USERREG +for /f "usebackq delims=" %%a in (`reg query "HKU\%~1\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\BannerStore" ^| findstr /i /c:"OneDrive"`) do ( + reg delete "%%a" /f > nul 2>&1 +) +for /f "usebackq delims=" %%a in (`reg query "HKU\%~1\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\AutoplayHandlers\Handlers" ^| findstr /i /c:"OneDrive"`) do ( + reg delete "%%a" /f > nul 2>&1 +) +for /f "usebackq delims=" %%a in (`reg query "HKU\%~1\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths" ^| findstr /i /c:"OneDrive"`) do ( + reg delete "%%a" /f > nul 2>&1 +) +for /f "usebackq delims=" %%a in (`reg query "HKU\%~1\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" ^| findstr /i /c:"OneDrive"`) do ( + reg delete "%%a" /f > nul 2>&1 +) + +reg delete "HKU\%~1\Environment" /v "OneDrive" /f > nul 2>&1 reg delete "HKU\%~1\Software\Microsoft\Windows\CurrentVersion\Run" /v "OneDriveSetup" /f > nul 2>&1 \ No newline at end of file diff --git a/src/playbook/Executables/STARTMENU.cmd b/src/playbook/Executables/STARTMENU.cmd index 560b294187..eae8997799 100644 --- a/src/playbook/Executables/STARTMENU.cmd +++ b/src/playbook/Executables/STARTMENU.cmd @@ -1,22 +1,22 @@ -@echo off - -copy /y "Layout.xml" "%SystemDrive%\Users\Default\AppData\Local\Microsoft\Windows\Shell\LayoutModification.xml" > nul - -:: If the "Volatile Environment" key exists, that means it is a proper user. Built in accounts/SIDs don't have this key. -for /f "usebackq tokens=2 delims=\" %%a in (`reg query "HKEY_USERS" ^| findstr /r /x /c:"HKEY_USERS\\S-.*" /c:"HKEY_USERS\\AME_UserHive_[^_]*"`) do ( - reg query "HKEY_USERS\%%a" | findstr /c:"Volatile Environment" /c:"AME_UserHive_" > nul && ( - for /f "usebackq tokens=4* delims= " %%c in (`reg query "HKU\%%a\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "Local AppData" ^| findstr /r /x /c:".*Local AppData[ ]*REG_SZ[ ].*"`) do ( - copy /y "Layout.xml" "%%c\Microsoft\Windows\Shell\LayoutModification.xml" > nul - - rem Clear Start Menu pinned items - for /f "usebackq delims=" %%d in (`dir /b "%%c\Packages" /a:d ^| findstr /c:"Microsoft.Windows.StartMenuExperienceHost"`) do ( - for /f "usebackq delims=" %%e in (`dir /b "%%c\Packages\%%d\LocalState" /a:-d ^| findstr /R /c:"start.\.bin" /c:"start\.bin"`) do ( - del /q /f "%%c\Packages\%%d\LocalState\%%e" > nul 2>&1 - ) - ) - ) - for /f "usebackq delims=" %%c in (`reg query "HKU\%%a\SOFTWARE\Microsoft\Windows\CurrentVersion\CloudStore\Store\Cache\DefaultAccount" ^| findstr /c:"start.tilegrid"`) do ( - reg delete "%%c" /f > nul 2>&1 - ) - ) -) +@echo off + +copy /y "Layout.xml" "%SystemDrive%\Users\Default\AppData\Local\Microsoft\Windows\Shell\LayoutModification.xml" > nul + +:: If the "Volatile Environment" key exists, that means it is a proper user. Built in accounts/SIDs don't have this key. +for /f "usebackq tokens=2 delims=\" %%a in (`reg query "HKEY_USERS" ^| findstr /r /x /c:"HKEY_USERS\\S-.*" /c:"HKEY_USERS\\AME_UserHive_[^_]*"`) do ( + reg query "HKEY_USERS\%%a" | findstr /c:"Volatile Environment" /c:"AME_UserHive_" > nul && ( + for /f "usebackq tokens=4* delims= " %%c in (`reg query "HKU\%%a\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "Local AppData" ^| findstr /r /x /c:".*Local AppData[ ]*REG_SZ[ ].*"`) do ( + copy /y "Layout.xml" "%%c\Microsoft\Windows\Shell\LayoutModification.xml" > nul + + rem Clear Start Menu pinned items + for /f "usebackq delims=" %%d in (`dir /b "%%c\Packages" /a:d ^| findstr /c:"Microsoft.Windows.StartMenuExperienceHost"`) do ( + for /f "usebackq delims=" %%e in (`dir /b "%%c\Packages\%%d\LocalState" /a:-d ^| findstr /R /c:"start.\.bin" /c:"start\.bin"`) do ( + del /q /f "%%c\Packages\%%d\LocalState\%%e" > nul 2>&1 + ) + ) + ) + for /f "usebackq delims=" %%c in (`reg query "HKU\%%a\SOFTWARE\Microsoft\Windows\CurrentVersion\CloudStore\Store\Cache\DefaultAccount" ^| findstr /c:"start.tilegrid"`) do ( + reg delete "%%c" /f > nul 2>&1 + ) + ) +)