Skip to content

Commit

Permalink
fix: spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Xyueta committed Sep 19, 2023
1 parent e8999d0 commit 9f85d0a
Show file tree
Hide file tree
Showing 3 changed files with 206 additions and 206 deletions.
274 changes: 137 additions & 137 deletions src/playbook/Executables/AtlasModules/Scripts/online-sxs.cmd
Original file line number Diff line number Diff line change
@@ -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}
}
94 changes: 47 additions & 47 deletions src/playbook/Executables/ONED.cmd
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 9f85d0a

Please sign in to comment.