20 changed files with 856 additions and 1654 deletions
@ -1,81 +0,0 @@
@@ -1,81 +0,0 @@
|
||||
@setlocal DisableDelayedExpansion |
||||
@echo off |
||||
set _args= |
||||
set _args=%* |
||||
if not defined _args goto :NoProgArgs |
||||
for %%A in (%_args%) do ( |
||||
if /i "%%A"=="-wow" set _rel1=1 |
||||
if /i "%%A"=="-arm" set _rel2=1 |
||||
) |
||||
:NoProgArgs |
||||
set "_cmdf=%~f0" |
||||
if exist "%SystemRoot%\Sysnative\cmd.exe" if not defined _rel1 ( |
||||
setlocal EnableDelayedExpansion |
||||
start %SystemRoot%\Sysnative\cmd.exe /c ""!_cmdf!" -wow" |
||||
exit /b |
||||
) |
||||
if exist "%SystemRoot%\SysArm32\cmd.exe" if /i %PROCESSOR_ARCHITECTURE%==AMD64 if not defined _rel2 ( |
||||
setlocal EnableDelayedExpansion |
||||
start %SystemRoot%\SysArm32\cmd.exe /c ""!_cmdf!" -arm" |
||||
exit /b |
||||
) |
||||
set "SysPath=%SystemRoot%\System32" |
||||
if exist "%SystemRoot%\Sysnative\reg.exe" (set "SysPath=%SystemRoot%\Sysnative") |
||||
set "Path=%SysPath%;%SystemRoot%;%SysPath%\Wbem;%SysPath%\WindowsPowerShell\v1.0\" |
||||
reg query HKU\S-1-5-19 >nul 2>&1 || ( |
||||
set "msg=ERROR: right click on the script and 'Run as administrator'" |
||||
goto :end |
||||
) |
||||
for /f "tokens=6 delims=[]. " %%G in ('ver') do set winbuild=%%G |
||||
if %winbuild% LSS 7601 ( |
||||
set "msg=ERROR: Windows 7 SP1 is the minimum supported OS" |
||||
goto :end |
||||
) |
||||
set "_work=%~dp0bin" |
||||
setlocal EnableDelayedExpansion |
||||
pushd "!_work!" |
||||
if not exist "OLicenseCleanup.vbs" ( |
||||
set "msg=ERROR: required file OLicenseCleanup.vbs is missing" |
||||
goto :end |
||||
) |
||||
set "_Nul1=1>nul" |
||||
set "_Nul2=2>nul" |
||||
set "_Nul6=2^>nul" |
||||
set "_Nul3=1>nul 2>nul" |
||||
|
||||
title Remove Office Subscription Licenses |
||||
echo. |
||||
echo ============================================================ |
||||
echo. |
||||
echo. |
||||
choice /C YN /N /M "Continue with removing Office subscription licenses? [y/n]: " |
||||
if errorlevel 2 goto :eof |
||||
if errorlevel 1 goto :main |
||||
|
||||
:main |
||||
cls |
||||
echo. |
||||
echo ============================================================ |
||||
echo Executing OLicenseCleanup.vbs |
||||
echo ============================================================ |
||||
%_Nul3% cscript //Nologo //B OLicenseCleanup.vbs |
||||
|
||||
if %winbuild% GEQ 17133 if exist "WAMAccounts.ps1" ( |
||||
echo. |
||||
echo ============================================================ |
||||
echo Executing WAMAccounts.ps1 |
||||
echo ============================================================ |
||||
%_Nul3% powershell -ep unrestricted -nop -c "try {& .\WAMAccounts.ps1} catch {}" |
||||
) |
||||
set "msg=Finished. It's recommended to restart the system." |
||||
goto :end |
||||
|
||||
:end |
||||
echo. |
||||
echo ============================================================ |
||||
echo %msg% |
||||
echo ============================================================ |
||||
echo. |
||||
echo Press any key to exit. |
||||
pause >nul |
||||
goto :eof |
@ -1,276 +0,0 @@
@@ -1,276 +0,0 @@
|
||||
<!-- : Begin batch script |
||||
@setlocal DisableDelayedExpansion |
||||
@echo off |
||||
set _args= |
||||
set _args=%* |
||||
if not defined _args goto :NoProgArgs |
||||
for %%A in (%_args%) do ( |
||||
if /i "%%A"=="-wow" set _rel1=1 |
||||
if /i "%%A"=="-arm" set _rel2=1 |
||||
) |
||||
:NoProgArgs |
||||
set "_cmdf=%~f0" |
||||
if exist "%SystemRoot%\Sysnative\cmd.exe" if not defined _rel1 ( |
||||
setlocal EnableDelayedExpansion |
||||
start %SystemRoot%\Sysnative\cmd.exe /c ""!_cmdf!" -wow" |
||||
exit /b |
||||
) |
||||
if exist "%SystemRoot%\SysArm32\cmd.exe" if /i %PROCESSOR_ARCHITECTURE%==AMD64 if not defined _rel2 ( |
||||
setlocal EnableDelayedExpansion |
||||
start %SystemRoot%\SysArm32\cmd.exe /c ""!_cmdf!" -arm" |
||||
exit /b |
||||
) |
||||
set "SysPath=%SystemRoot%\System32" |
||||
if exist "%SystemRoot%\Sysnative\reg.exe" (set "SysPath=%SystemRoot%\Sysnative") |
||||
set "Path=%SysPath%;%SystemRoot%;%SysPath%\Wbem;%SysPath%\WindowsPowerShell\v1.0\" |
||||
reg query HKU\S-1-5-19 >nul 2>&1 || ( |
||||
set "msg=ERROR: right click on the script and 'Run as administrator'" |
||||
goto :end |
||||
) |
||||
for /f "tokens=6 delims=[]. " %%G in ('ver') do set winbuild=%%G |
||||
if %winbuild% LSS 7601 ( |
||||
set "msg=ERROR: Windows 7 SP1 is the minimum supported OS" |
||||
goto :end |
||||
) |
||||
set _cwmi=0 |
||||
for %%# in (wmic.exe) do @if not "%%~$PATH:#"=="" ( |
||||
wmic path Win32_ComputerSystem get CreationClassName /value 2>nul | find /i "ComputerSystem" 1>nul && set _cwmi=1 |
||||
) |
||||
set _pwsh=1 |
||||
for %%# in (powershell.exe) do @if "%%~$PATH:#"=="" set _pwsh=0 |
||||
set "_csq=cscript.exe //NoLogo //Job:WmiQuery "%~nx0?.wsf"" |
||||
set "_csm=cscript.exe //NoLogo //Job:WmiMethod "%~nx0?.wsf"" |
||||
set WMI_VBS=0 |
||||
if %_cwmi% EQU 0 set WMI_VBS=1 |
||||
set _WSH=1 |
||||
reg query "HKCU\SOFTWARE\Microsoft\Windows Script Host\Settings" /v Enabled 2>nul | find /i "0x0" 1>nul && (set _WSH=0) |
||||
reg query "HKLM\SOFTWARE\Microsoft\Windows Script Host\Settings" /v Enabled 2>nul | find /i "0x0" 1>nul && (set _WSH=0) |
||||
set "_oApp=0ff1ce15-a989-479d-af46-f275c6370663" |
||||
set "_oA14=59a52881-a989-479d-af46-f275c6370663" |
||||
set "_Common=%CommonProgramFiles%" |
||||
if defined PROCESSOR_ARCHITEW6432 set "_Common=%CommonProgramW6432%" |
||||
if /i "%PROCESSOR_ARCHITECTURE%"=="amd64" set "xBit=x64" |
||||
if /i "%PROCESSOR_ARCHITECTURE%"=="arm64" set "xBit=x86" |
||||
if /i "%PROCESSOR_ARCHITECTURE%"=="x86" if "%PROCESSOR_ARCHITEW6432%"=="" set "xBit=x86" |
||||
if /i "%PROCESSOR_ARCHITEW6432%"=="amd64" set "xBit=x64" |
||||
if /i "%PROCESSOR_ARCHITEW6432%"=="arm64" set "xBit=x86" |
||||
set "_file=%_Common%\Microsoft Shared\ClickToRun\OfficeClickToRun.exe" |
||||
set "_fil2=%CommonProgramFiles(x86)%\Microsoft Shared\ClickToRun\OfficeClickToRun.exe" |
||||
set "_work=%~dp0bin" |
||||
setlocal EnableDelayedExpansion |
||||
pushd "!_work!" |
||||
if not exist "%xBit%\cleanospp.exe" ( |
||||
set "msg=ERROR: required file cleanospp.exe is missing" |
||||
goto :end |
||||
) |
||||
for %%# in (OffScrub_O16msi.vbs,OffScrubC2R.vbs,OLicenseCleanup.vbs) do ( |
||||
if not exist ".\%%#" (set "msg=ERROR: required file %%# is missing"&goto :end) |
||||
) |
||||
set "_Nul1=1>nul" |
||||
set "_Nul2=2>nul" |
||||
set "_Nul6=2^>nul" |
||||
set "_Nul3=1>nul 2>nul" |
||||
|
||||
title Office Scrubber |
||||
set OfficeC2R=0 |
||||
sc query ClickToRunSvc %_Nul3% && set OfficeC2R=1 |
||||
sc query OfficeSvc %_Nul3% && set OfficeC2R=1 |
||||
reg query HKLM\SOFTWARE\Microsoft\Office\ClickToRun\Configuration /v ProductReleaseIds %_Nul3% && ( |
||||
set OfficeC2R=1 |
||||
for /f "skip=2 tokens=2*" %%a in ('"reg query HKLM\SOFTWARE\Microsoft\Office\ClickToRun\Configuration /v Platform" %_Nul6%') do set "_plat=%%b" |
||||
) |
||||
if %OfficeC2R% equ 0 reg query HKLM\SOFTWARE\WOW6432Node\Microsoft\Office\ClickToRun\Configuration /v ProductReleaseIds %_Nul3% && ( |
||||
set OfficeC2R=1 |
||||
for /f "skip=2 tokens=2*" %%a in ('"reg query HKLM\SOFTWARE\WOW6432Node\Microsoft\Office\ClickToRun\Configuration /v Platform" %_Nul6%') do set "_plat=%%b" |
||||
) |
||||
if exist "!_file!" set OfficeC2R=1 |
||||
if exist "!_fil2!" if /i "%PROCESSOR_ARCHITECTURE%"=="arm64" set OfficeC2R=1 |
||||
set OfficeMSI=0 |
||||
for /f "skip=2 tokens=2*" %%a in ('"reg query HKLM\SOFTWARE\Microsoft\Office\16.0\Common\InstallRoot /v Path" %_Nul6%') do if exist "%%b\OSPP.VBS" set OfficeMSI=1 |
||||
for /f "skip=2 tokens=2*" %%a in ('"reg query HKLM\SOFTWARE\Wow6432Node\Microsoft\Office\16.0\Common\InstallRoot /v Path" %_Nul6%') do if exist "%%b\OSPP.VBS" set OfficeMSI=1 |
||||
if %OfficeC2R% equ 1 if not defined _plat ( |
||||
if exist "%ProgramFiles(x86)%\Microsoft Office\Office16\OSPP.VBS" (set "_plat=x86") else (set "_plat=%xBit%") |
||||
) |
||||
set OfficeUWP=0 |
||||
if %winbuild% GEQ 10240 reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\msoxmled.exe" %_Nul3% && ( |
||||
dir /b "%ProgramFiles%\WindowsApps\Microsoft.Office.Desktop*" %_Nul3% && set OfficeUWP=1 |
||||
dir /b "%ProgramW6432%\WindowsApps\Microsoft.Office.Desktop*" %_Nul3% && set OfficeUWP=1 |
||||
dir /b "%ProgramFiles(x86)%\WindowsApps\Microsoft.Office.Desktop*" %_Nul3% && set OfficeUWP=1 |
||||
) |
||||
|
||||
if %OfficeC2R% equ 0 if %OfficeMSI% equ 0 if %OfficeUWP% equ 0 ( |
||||
echo. |
||||
echo ============================================================ |
||||
echo No installed Office ClickToRun or Office 2016 MSI detected |
||||
echo. |
||||
echo. |
||||
choice /C YN /N /M "Continue with scrubbing Office anyway? [y/n]: " |
||||
if errorlevel 2 goto :eof |
||||
if errorlevel 1 goto :main |
||||
) |
||||
echo. |
||||
echo ============================================================ |
||||
if %OfficeC2R% equ 1 echo Detected Office C2R |
||||
if %OfficeMSI% equ 1 echo Detected Office 2016 MSI |
||||
if %OfficeUWP% equ 1 echo Detected Office UWP Apps |
||||
echo. |
||||
echo. |
||||
choice /C YN /N /M "Continue with scrubbing detected Office? [y/n]: " |
||||
if errorlevel 2 goto :eof |
||||
if errorlevel 1 goto :main |
||||
|
||||
:main |
||||
cls |
||||
if %OfficeC2R% equ 0 if %OfficeMSI% equ 0 if %OfficeUWP% equ 0 goto :proceed |
||||
echo. |
||||
echo ============================================================ |
||||
echo Uninstalling Product Key^(s) |
||||
echo ============================================================ |
||||
call :cKMS %_Nul3% |
||||
if %WMI_VBS% NEQ 0 cd bin |
||||
|
||||
:proceed |
||||
if exist "!_file!" ( |
||||
echo. |
||||
echo ============================================================ |
||||
echo Executing OfficeClickToRun.exe |
||||
echo ============================================================ |
||||
%_Nul3% start "" /WAIT "!_file!" platform=%_plat% productstoremove=AllProducts displaylevel=False |
||||
) |
||||
if exist "!_fil2!" if /i "%PROCESSOR_ARCHITECTURE%"=="arm64" ( |
||||
echo. |
||||
echo ============================================================ |
||||
echo Executing OfficeClickToRun.exe |
||||
echo ============================================================ |
||||
%_Nul3% start "" /WAIT "!_fil2!" platform=%_plat% productstoremove=AllProducts displaylevel=False |
||||
) |
||||
echo. |
||||
echo ============================================================ |
||||
echo Executing OffScrubC2R.vbs |
||||
echo ============================================================ |
||||
%_Nul3% cscript //Nologo //B OffScrubC2R.vbs ALL /OSE /QUIET /NOCANCEL |
||||
echo. |
||||
echo ============================================================ |
||||
echo Executing OffScrub_O16msi.vbs |
||||
echo ============================================================ |
||||
%_Nul3% cscript //Nologo //B OffScrub_O16msi.vbs ALL /OSE /QUIET /NOCANCEL /NOREBOOT /FORCE /DELETEUSERSETTINGS /ECI |
||||
echo. |
||||
echo ============================================================ |
||||
echo Executing OLicenseCleanup.vbs |
||||
echo ============================================================ |
||||
%_Nul3% cscript //Nologo //B OLicenseCleanup.vbs |
||||
|
||||
if %winbuild% GEQ 17133 if exist "WAMAccounts.ps1" if %_pwsh% equ 1 ( |
||||
echo. |
||||
echo ============================================================ |
||||
echo Executing WAMAccounts.ps1 |
||||
echo ============================================================ |
||||
%_Nul3% powershell -ep unrestricted -nop -c "try {& .\WAMAccounts.ps1} catch {}" |
||||
) |
||||
if %OfficeUWP% equ 1 if %_pwsh% equ 1 ( |
||||
echo. |
||||
echo ============================================================ |
||||
echo Removing Office UWP Apps |
||||
echo ============================================================ |
||||
%_Nul3% powershell -nop -c "Get-AppXPackage -Name '*Microsoft.Office.Desktop*' | Foreach {Remove-AppxPackage $_.PackageFullName}" |
||||
%_Nul3% powershell -nop -c "Get-AppXProvisionedPackage -Online | Where DisplayName -Like '*Microsoft.Office.Desktop*' | Remove-AppXProvisionedPackage -Online" |
||||
) |
||||
%xBit%\cleanospp.exe %_Nul3% |
||||
reg delete HKCU\Software\Microsoft\Office /f %_Nul3% |
||||
reg delete HKCU\Software\Policies\Microsoft\Office\16.0 /f %_Nul3% |
||||
reg delete HKLM\SOFTWARE\Microsoft\Office /f %_Nul3% |
||||
reg delete HKLM\SOFTWARE\Policies\Microsoft\Office\16.0 /f %_Nul3% |
||||
reg delete HKLM\SOFTWARE\Wow6432Node\Microsoft\Office /f %_Nul3% |
||||
reg delete HKLM\SOFTWARE\Wow6432Node\Policies\Microsoft\Office\16.0 /f %_Nul3% |
||||
for /f %%# in ('"dir /b %SystemRoot%\temp\ose*.exe" %_Nul6%') do taskkill /t /f /IM %%# %_Nul3% |
||||
del /f /q "%SystemRoot%\temp\*" %_Nul3% |
||||
del /f /q "%SystemRoot%\temp\*.log" %_Nul3% |
||||
del /f /q "%temp%\*.log" %_Nul3% |
||||
|
||||
if exist "%SysPath%\spp\store_test\2.0\tokens.dat" ( |
||||
echo. |
||||
echo ============================================================ |
||||
echo Refreshing Windows Insider Preview Licenses... |
||||
echo ============================================================ |
||||
echo. |
||||
cscript //Nologo //B %SysPath%\slmgr.vbs /rilc |
||||
if !ERRORLEVEL! NEQ 0 cscript //Nologo //B %SysPath%\slmgr.vbs /rilc |
||||
) |
||||
set "msg=Finished. It's recommended to restart the system." |
||||
goto :end |
||||
|
||||
:cKMS |
||||
set "OPPk=SOFTWARE\Microsoft\OfficeSoftwareProtectionPlatform" |
||||
set "SPPk=SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform" |
||||
if %winbuild% geq 9200 ( |
||||
set spp=SoftwareLicensingProduct |
||||
reg delete "HKLM\%SPPk%\0ff1ce15-a989-479d-af46-f275c6370663" /f |
||||
reg delete "HKEY_USERS\S-1-5-20\%SPPk%\0ff1ce15-a989-479d-af46-f275c6370663" /f |
||||
) else ( |
||||
set spp=OfficeSoftwareProtectionProduct |
||||
reg delete "HKLM\%OPPk%\0ff1ce15-a989-479d-af46-f275c6370663" /f |
||||
reg delete "HKEY_USERS\S-1-5-20\%OPPk%" /f |
||||
) |
||||
if %_WSH% EQU 0 if %WMI_VBS% NEQ 0 goto :eof |
||||
if %WMI_VBS% NEQ 0 cd .. |
||||
set "_ocq=Name LIKE 'Office%%' AND PartialProductKey is not NULL" |
||||
set "_qr="wmic path %spp% where (%_ocq%) get ID /VALUE"" |
||||
if %WMI_VBS% NEQ 0 set "_qr=%_csq% %spp% "%_ocq%" ID" |
||||
for /f "tokens=2 delims==" %%G in ('%_qr% %_Nul6%') do (set app=%%G&call :cAPP %_Nul3%) |
||||
goto :eof |
||||
|
||||
:cAPP |
||||
if %winbuild% geq 9200 ( |
||||
reg delete "HKLM\%SPPk%\%_oApp%\%app%" /f %_Null% |
||||
) else ( |
||||
reg delete "HKLM\%OPPk%\%_oA14%\%app%" /f %_Null% |
||||
reg delete "HKLM\%OPPk%\%_oApp%\%app%" /f %_Null% |
||||
) |
||||
set "_qr=wmic path %spp% where ID='%app%' call UninstallProductKey" |
||||
if %WMI_VBS% NEQ 0 set "_qr=%_csm% "%spp%.ID='%app%'" UninstallProductKey" |
||||
%_qr% |
||||
goto :eof |
||||
|
||||
:end |
||||
echo. |
||||
echo ============================================================ |
||||
echo %msg% |
||||
echo ============================================================ |
||||
echo. |
||||
echo Press any key to exit. |
||||
pause >nul |
||||
goto :eof |
||||
|
||||
----- Begin wsf script ---> |
||||
<package> |
||||
<job id="WmiQuery"> |
||||
<script language="VBScript"> |
||||
If WScript.Arguments.Count = 3 Then |
||||
wExc = "Select " & WScript.Arguments.Item(2) & " from " & WScript.Arguments.Item(0) & " where " & WScript.Arguments.Item(1) |
||||
wGet = WScript.Arguments.Item(2) |
||||
Else |
||||
wExc = "Select " & WScript.Arguments.Item(1) & " from " & WScript.Arguments.Item(0) |
||||
wGet = WScript.Arguments.Item(1) |
||||
End If |
||||
Set objCol = GetObject("winmgmts:\\.\root\CIMV2").ExecQuery(wExc,,48) |
||||
For Each objItm in objCol |
||||
For each Prop in objItm.Properties_ |
||||
If LCase(Prop.Name) = LCase(wGet) Then |
||||
WScript.Echo Prop.Name & "=" & Prop.Value |
||||
Exit For |
||||
End If |
||||
Next |
||||
Next |
||||
</script> |
||||
</job> |
||||
<job id="WmiMethod"> |
||||
<script language="VBScript"> |
||||
On Error Resume Next |
||||
wPath = WScript.Arguments.Item(0) |
||||
wMethod = WScript.Arguments.Item(1) |
||||
Set objCol = GetObject("winmgmts:\\.\root\CIMV2:" & wPath) |
||||
objCol.ExecMethod_(wMethod) |
||||
WScript.Quit Err.Number |
||||
</script> |
||||
</job> |
||||
</package> |
@ -0,0 +1,633 @@
@@ -0,0 +1,633 @@
|
||||
<!-- : Begin batch script |
||||
@setlocal DisableDelayedExpansion |
||||
@echo off |
||||
set _elev= |
||||
set _args= |
||||
set _args=%* |
||||
if not defined _args goto :NoProgArgs |
||||
for %%A in (%_args%) do ( |
||||
if /i "%%A"=="-elevated" set _elev=1 |
||||
if /i "%%A"=="-wow" set _rel1=1 |
||||
if /i "%%A"=="-arm" set _rel2=1 |
||||
) |
||||
:NoProgArgs |
||||
set "_cmdf=%~f0" |
||||
if exist "%SystemRoot%\Sysnative\cmd.exe" if not defined _rel1 ( |
||||
setlocal EnableDelayedExpansion |
||||
start %SystemRoot%\Sysnative\cmd.exe /c ""!_cmdf!" -wow" |
||||
exit /b |
||||
) |
||||
if exist "%SystemRoot%\SysArm32\cmd.exe" if /i %PROCESSOR_ARCHITECTURE%==AMD64 if not defined _rel2 ( |
||||
setlocal EnableDelayedExpansion |
||||
start %SystemRoot%\SysArm32\cmd.exe /c ""!_cmdf!" -arm" |
||||
exit /b |
||||
) |
||||
set "SysPath=%SystemRoot%\System32" |
||||
set "Path=%SystemRoot%\System32;%SystemRoot%\System32\Wbem;%SystemRoot%\System32\WindowsPowerShell\v1.0\" |
||||
if exist "%SystemRoot%\Sysnative\reg.exe" ( |
||||
set "SysPath=%SystemRoot%\Sysnative" |
||||
set "Path=%SystemRoot%\Sysnative;%SystemRoot%\Sysnative\Wbem;%SystemRoot%\Sysnative\WindowsPowerShell\v1.0\;%Path%" |
||||
) |
||||
set "_psc=powershell -nop -c" |
||||
|
||||
1>nul 2>nul reg query HKU\S-1-5-19 && ( |
||||
goto :Passed |
||||
) || ( |
||||
if defined _elev goto :E_Admin |
||||
) |
||||
|
||||
set _PSarg="""%~f0""" %_args% -elevated |
||||
set _PSarg=%_PSarg:'=''% |
||||
|
||||
(1>nul 2>nul cscript //NoLogo "%~f0?.wsf" //job:ELAV /File:"%~f0" %_args% -elevated) && ( |
||||
exit /b |
||||
) || ( |
||||
call setlocal EnableDelayedExpansion |
||||
1>nul 2>nul %SysPath%\WindowsPowerShell\v1.0\%_psc% "start cmd.exe -arg '/c \"!_PSarg!\"' -verb runas" && ( |
||||
exit /b |
||||
) || ( |
||||
goto :E_Admin |
||||
) |
||||
) |
||||
|
||||
:Passed |
||||
for /f "tokens=6 delims=[]. " %%G in ('ver') do set winbuild=%%G |
||||
if %winbuild% LSS 7601 ( |
||||
set "msg=ERROR: Windows 7 SP1 is the minimum supported OS" |
||||
goto :TheEnd |
||||
) |
||||
set _cwmi=0 |
||||
for %%# in (wmic.exe) do @if not "%%~$PATH:#"=="" ( |
||||
wmic path Win32_ComputerSystem get CreationClassName /value 2>nul | find /i "ComputerSystem" 1>nul && set _cwmi=1 |
||||
) |
||||
set _pwsh=1 |
||||
for %%# in (powershell.exe) do @if "%%~$PATH:#"=="" set _pwsh=0 |
||||
set "_csq=cscript.exe //NoLogo //Job:WmiQuery "%~nx0?.wsf"" |
||||
set "_csm=cscript.exe //NoLogo //Job:WmiMethod "%~nx0?.wsf"" |
||||
set WMI_VBS=0 |
||||
if %_cwmi% EQU 0 set WMI_VBS=1 |
||||
set _WSH=1 |
||||
reg query "HKCU\SOFTWARE\Microsoft\Windows Script Host\Settings" /v Enabled 2>nul | find /i "0x0" 1>nul && (set _WSH=0) |
||||
reg query "HKLM\SOFTWARE\Microsoft\Windows Script Host\Settings" /v Enabled 2>nul | find /i "0x0" 1>nul && (set _WSH=0) |
||||
set "_oApp=0ff1ce15-a989-479d-af46-f275c6370663" |
||||
set "_oA14=59a52881-a989-479d-af46-f275c6370663" |
||||
set "OPPk=SOFTWARE\Microsoft\OfficeSoftwareProtectionPlatform" |
||||
set "SPPk=SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform" |
||||
set "_para=ALL /QUIET /OSE /NOCANCEL /FORCE /ENDCURRENTINSTALLS /DELETEUSERSETTINGS /CLEARADDINREG /REMOVELYNC" |
||||
if /i "%PROCESSOR_ARCHITECTURE%"=="amd64" set "xBit=x64"&set "xOS=x64" |
||||
if /i "%PROCESSOR_ARCHITECTURE%"=="arm64" set "xBit=x86"&set "xOS=A64" |
||||
if /i "%PROCESSOR_ARCHITECTURE%"=="x86" if "%PROCESSOR_ARCHITEW6432%"=="" set "xBit=x86"&set "xOS=x86" |
||||
if /i "%PROCESSOR_ARCHITEW6432%"=="amd64" set "xBit=x64"&set "xOS=x64" |
||||
if /i "%PROCESSOR_ARCHITEW6432%"=="arm64" set "xBit=x86"&set "xOS=A64" |
||||
set "_Common=%CommonProgramFiles%" |
||||
if defined PROCESSOR_ARCHITEW6432 set "_Common=%CommonProgramW6432%" |
||||
set "_file=%_Common%\Microsoft Shared\ClickToRun\OfficeClickToRun.exe" |
||||
set "_fil2=%CommonProgramFiles(x86)%\Microsoft Shared\ClickToRun\OfficeClickToRun.exe" |
||||
set "_work=%~dp0bin" |
||||
set "_Local=%LocalAppData%" |
||||
set "_cscript=cscript //Nologo //B" |
||||
setlocal EnableDelayedExpansion |
||||
pushd "!_work!" |
||||
if not exist "%xBit%\cleanospp.exe" ( |
||||
set "msg=ERROR: required file cleanospp.exe is missing" |
||||
goto :TheEnd |
||||
) |
||||
for %%# in (OffScrubC2R,OffScrub_O16msi,OffScrub_O15msi,OffScrub10,OffScrub07,OffScrub03) do ( |
||||
if not exist ".\%%#.vbs" (set "msg=ERROR: required file %%# is missing"&goto :TheEnd) |
||||
) |
||||
set "_Nul1=1>nul" |
||||
set "_Nul2=2>nul" |
||||
set "_Nul6=2^>nul" |
||||
set "_Nul3=1>nul 2>nul" |
||||
|
||||
title Office Scrubber |
||||
echo. |
||||
echo ============================================================ |
||||
echo Detecting Office versions, please wait... |
||||
|
||||
set OsppHook=1 |
||||
sc query osppsvc %_Nul3% |
||||
if %ERRORLEVEL% EQU 1060 set OsppHook=0 |
||||
|
||||
for %%A in (11,12,14,15,16) do call :officeMSI %%A |
||||
|
||||
set _O16CTR=0 |
||||
sc query ClickToRunSvc %_Nul3% && set _O16CTR=1 |
||||
reg query HKLM\SOFTWARE\Microsoft\Office\ClickToRun\Configuration /v ProductReleaseIds %_Nul3% && ( |
||||
set _O16CTR=1 |
||||
for /f "skip=2 tokens=2*" %%a in ('"reg query HKLM\SOFTWARE\Microsoft\Office\ClickToRun\Configuration /v Platform" %_Nul6%') do set "_plat=%%b" |
||||
) |
||||
if not %xOS%==x86 if %_O16CTR% EQU 0 reg query HKLM\SOFTWARE\WOW6432Node\Microsoft\Office\ClickToRun\Configuration /v ProductReleaseIds %_Nul3% && ( |
||||
set _O16CTR=1 |
||||
for /f "skip=2 tokens=2*" %%a in ('"reg query HKLM\SOFTWARE\WOW6432Node\Microsoft\Office\ClickToRun\Configuration /v Platform" %_Nul6%') do set "_plat=%%b" |
||||
) |
||||
if exist "!_file!" set _O16CTR=1 |
||||
if exist "!_fil2!" if /i "%PROCESSOR_ARCHITECTURE%"=="arm64" set _O16CTR=1 |
||||
if %_O16CTR% EQU 1 if not defined _plat ( |
||||
if exist "%ProgramFiles(x86)%\Microsoft Office\Office16\OSPP.VBS" (set "_plat=x86") else (set "_plat=%xBit%") |
||||
) |
||||
|
||||
set _O15CTR=0 |
||||
sc query OfficeSvc %_Nul3% && set _O15CTR=1 |
||||
reg query HKLM\SOFTWARE\Microsoft\Office\15.0\ClickToRun /v InstallPath %_Nul3% && ( |
||||
set _O15CTR=1 |
||||
) |
||||
if %_O15CTR% EQU 0 reg query HKLM\SOFTWARE\WOW6432Node\Microsoft\Office\15.0\ClickToRun /v InstallPath %_Nul3% && ( |
||||
set _O15CTR=1 |
||||
) |
||||
if %_O15CTR% EQU 0 reg query HKLM\SOFTWARE\Microsoft\Office\15.0\ClickToRun\propertyBag /v productreleaseid %_Nul3% && ( |
||||
set _O15CTR=1 |
||||
) |
||||
if %_O15CTR% EQU 0 reg query HKLM\SOFTWARE\WOW6432Node\Microsoft\Office\15.0\ClickToRun\propertyBag /v productreleaseid %_Nul3% && ( |
||||
set _O15CTR=1 |
||||
) |
||||
|
||||
set _O14CTR=0 |
||||
if %xOS%==x86 reg query HKLM\SOFTWARE\Microsoft\Office\14.0\CVH /f Click2run /k %_Nul3% && set _O14CTR=1 |
||||
if not %xOS%==x86 reg query HKLM\SOFTWARE\Wow6432Node\Microsoft\Office\14.0\CVH /f Click2run /k %_Nul3% && set _O14CTR=1 |
||||
|
||||
set _O16UWP=0 |
||||
if %winbuild% GEQ 10240 reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\msoxmled.exe" %_Nul3% && ( |
||||
dir /b "%ProgramFiles%\WindowsApps\Microsoft.Office.Desktop*" %_Nul3% && set _O16UWP=1 |
||||
if not %xOS%==x86 dir /b "%ProgramW6432%\WindowsApps\Microsoft.Office.Desktop*" %_Nul3% && set _O16UWP=1 |
||||
if not %xOS%==x86 dir /b "%ProgramFiles(x86)%\WindowsApps\Microsoft.Office.Desktop*" %_Nul3% && set _O16UWP=1 |
||||
) |
||||
|
||||
set kO16=HKCU\SOFTWARE\Microsoft\Office\16.0 |
||||
set _O16NXT=0 |
||||
dir /b /s /a:-d "!_Local!\Microsoft\Office\Licenses\*1*" %_Nul3% && set _O16NXT=1 |
||||
dir /b /s /a:-d "!ProgramData!\Microsoft\Office\Licenses\*1*" %_Nul3% && set _O16NXT=1 |
||||
reg query "%kO16%\Common\Licensing\LicensingNext" /v MigrationToV5Done %_Nul2% | find /i "0x1" %_Nul1% && set _O16NXT=1 |
||||
|
||||
set tOCTR=0&set "dOCTR=" |
||||
set tOM16=0&set "dOM16=" |
||||
set tOM15=0&set "dOM15=" |
||||
set tOM14=0&set "dOM14=" |
||||
set tOM12=0&set "dOM12=" |
||||
set tOM11=0&set "dOM11=" |
||||
set tOUWP=0&set "dOUWP=" |
||||
set "dONXT=" |
||||
if %_O15CTR% EQU 1 set tOCTR=1&set "dOCTR={*} / 2013" |
||||
if %_O16CTR% EQU 1 set tOCTR=1&set "dOCTR={*}" |
||||
if %_O16MSI% EQU 1 set tOM16=1&set "dOM16={*}" |
||||
if %_O15MSI% EQU 1 set tOM15=1&set "dOM15={*}" |
||||
if %_O14CTR% EQU 1 set tOM14=1&set "dOM14={*} / C2R" |
||||
if %_O14MSI% EQU 1 set tOM14=1&set "dOM14={*}" |
||||
if %_O12MSI% EQU 1 set tOM12=1&set "dOM12={*}" |
||||
if %_O11MSI% EQU 1 set tOM11=1&set "dOM11={*}" |
||||
if %_O16UWP% EQU 1 set tOUWP=1&set "dOUWP={*}" |
||||
if %_O16NXT% EQU 1 set "dONXT={*}" |
||||
|
||||
:Menu |
||||
set _er=0 |
||||
call :Hdr |
||||
echo [1] Scrub ALL |
||||
echo [2] Scrub Office C2R %dOCTR% |
||||
echo [3] Scrub Office 2016 %dOM16% |
||||
echo [4] Scrub Office 2013 %dOM15% |
||||
echo [5] Scrub Office 2010 %dOM14% |
||||
echo [6] Scrub Office 2007 %dOM12% |
||||
echo [7] Scrub Office 2003 %dOM11% |
||||
if %winbuild% GEQ 10240 echo [8] Scrub Office UWP %dOUWP% |
||||
echo. |
||||
echo. --- Office 2016 and later --- |
||||
echo [C] Clean vNext Licenses %dONXT% |
||||
echo [R] Remove all Licenses |
||||
echo [T] Reset C2R Licenses |
||||
echo [U] Uninstall all Keys |
||||
echo. |
||||
echo ============================================================ |
||||
choice /c 12345678CRTU0 /n /m "Choose a menu option, or press 0 to Exit: " |
||||
set _er=%ERRORLEVEL% |
||||
if %_er% EQU 13 goto :eof |
||||
if %_er% EQU 12 goto :KeysU |
||||
if %_er% EQU 11 goto :LcnsT |
||||
if %_er% EQU 10 goto :LcnsR |
||||
if %_er% EQU 9 goto :LcnsC |
||||
if %_er% EQU 8 (if %winbuild% GEQ 10240 (goto :sOUWP) else (goto :Menu)) |
||||
if %_er% EQU 7 goto :sOM11 |
||||
if %_er% EQU 6 goto :sOM12 |
||||
if %_er% EQU 5 goto :sOM14 |
||||
if %_er% EQU 4 goto :sOM15 |
||||
if %_er% EQU 3 goto :sOM16 |
||||
if %_er% EQU 2 goto :sOCTR |
||||
if %_er% EQU 1 goto :mALL |
||||
goto :Menu |
||||
|
||||
:mALL |
||||
set "aOCTR=NO %dOCTR%" |
||||
set "aOM16=NO %dOM16%" |
||||
set "aOM15=NO %dOM15%" |
||||
set "aOM14=NO %dOM14%" |
||||
set "aOM12=NO %dOM12%" |
||||
set "aOM11=NO %dOM11%" |
||||
set "aOUWP=NO %dOUWP%" |
||||
if %tOCTR% EQU 1 set "aOCTR=YES %dOCTR%" |
||||
if %tOM16% EQU 1 set "aOM16=YES %dOM16%" |
||||
if %tOM15% EQU 1 set "aOM15=YES %dOM15%" |
||||
if %tOM14% EQU 1 set "aOM14=YES %dOM14%" |
||||
if %tOM12% EQU 1 set "aOM12=YES %dOM12%" |
||||
if %tOM11% EQU 1 set "aOM11=YES %dOM11%" |
||||
if %tOUWP% EQU 1 set "aOUWP=YES %dOUWP%" |
||||
set _er=0 |
||||
call :Hdr |
||||
echo [1] Start the operation |
||||
echo [2] Office C2R : %aOCTR% |
||||
echo [3] Office 2016: %aOM16% |
||||
echo [4] Office 2013: %aOM15% |
||||
echo [5] Office 2010: %aOM14% |
||||
echo [6] Office 2007: %aOM12% |
||||
echo [7] Office 2003: %aOM11% |
||||
if %winbuild% GEQ 10240 echo [8] Office UWP : %aOUWP% |
||||
echo. |
||||
echo ------- |
||||
echo Notice: |
||||
echo It's recommended to only scrub detected versions {*} |
||||
echo selecting all is not necessary and will take a long time. |
||||
echo. |
||||
echo ============================================================ |
||||
choice /c 123456780 /n /m "Change menu options, or press 0 to Exit: " |
||||
set _er=%ERRORLEVEL% |
||||
if %_er% EQU 9 goto :eof |
||||
if %_er% EQU 8 (if %tOUWP% EQU 1 (set tOUWP=0) else (set tOUWP=1)&goto :mALL) |
||||
if %_er% EQU 7 (if %tOM11% EQU 1 (set tOM11=0) else (set tOM11=1)&goto :mALL) |
||||
if %_er% EQU 6 (if %tOM12% EQU 1 (set tOM12=0) else (set tOM12=1)&goto :mALL) |
||||
if %_er% EQU 5 (if %tOM14% EQU 1 (set tOM14=0) else (set tOM14=1)&goto :mALL) |
||||
if %_er% EQU 4 (if %tOM15% EQU 1 (set tOM15=0) else (set tOM15=1)&goto :mALL) |
||||
if %_er% EQU 3 (if %tOM16% EQU 1 (set tOM16=0) else (set tOM16=1)&goto :mALL) |
||||
if %_er% EQU 2 (if %tOCTR% EQU 1 (set tOCTR=0) else (set tOCTR=1)&goto :mALL) |
||||
if %_er% EQU 1 goto :sOALL |
||||
goto :mALL |
||||
|
||||
:Hdr |
||||
cls |
||||
echo ============================================================ |
||||
goto :eof |
||||
|
||||
:sOALL |
||||
call :Hdr |
||||
echo. |
||||
echo Uninstall Product Keys |
||||
%xBit%\cleanospp.exe -PKey %_Nul3% |
||||
call :cKMS %_Nul3% |
||||
if %tOCTR% EQU 1 call :rOCTR |
||||
if %tOUWP% EQU 1 if %_pwsh% EQU 1 call :rOUWP |
||||
if %tOM16% EQU 1 call :rOM16 |
||||
if %tOM15% EQU 1 call :rOM15 |
||||
if %tOM14% EQU 1 call :rOM14 |
||||
if %tOM12% EQU 1 call :rOM12 |
||||
if %tOM11% EQU 1 call :rOM11 |
||||
call :cSPP |
||||
goto :Fin |
||||
|
||||
:sOCTR |
||||
call :Hdr |
||||
call :rOCTR |
||||
if %_O15MSI% EQU 0 call :cSPP |
||||
goto :Fin |
||||
|
||||
:sOM16 |
||||
call :Hdr |
||||
call :rOM16 |
||||
if %_O15MSI% EQU 0 call :cSPP |
||||
goto :Fin |
||||
|
||||
:sOM15 |
||||
call :Hdr |
||||
call :rOM15 |
||||
if %_O16MSI% EQU 0 if %_O16CTR% EQU 0 if %_O16UWP% EQU 0 call :cSPP |
||||
goto :Fin |
||||
|
||||
:sOM14 |
||||
call :Hdr |
||||
call :rOM14 |
||||
goto :Fin |
||||
|
||||
:sOM12 |
||||
call :Hdr |
||||
call :rOM12 |
||||
goto :Fin |
||||
|
||||
:sOM11 |
||||
call :Hdr |
||||
call :rOM11 |
||||
goto :Fin |
||||
|
||||
:sOUWP |
||||
call :Hdr |
||||
if %_pwsh% EQU 0 ( |
||||
set "msg=ERROR: Windows Powershell is not detected." |
||||
goto :TheEnd |
||||
) |
||||
call :rOUWP |
||||
set "msg=Done." |
||||
goto :TheEnd |
||||
|
||||
:rOCTR |
||||
if exist "!_file!" ( |
||||
echo. |
||||
echo Execute OfficeClickToRun.exe |
||||
%_Nul3% start "" /WAIT "!_file!" platform=%_plat% productstoremove=AllProducts displaylevel=False |
||||
) |
||||
if exist "!_fil2!" if /i "%PROCESSOR_ARCHITECTURE%"=="arm64" ( |
||||
echo. |
||||
echo Execute OfficeClickToRun.exe |
||||
%_Nul3% start "" /WAIT "!_fil2!" platform=%_plat% productstoremove=AllProducts displaylevel=False |
||||
) |
||||
echo. |
||||
echo Scrub Office C2R |
||||
for %%A in (16,19,21) do call :cKpp %%A |
||||
if %_O15CTR% EQU 1 call :cKpp 15 |
||||
%_Nul3% %_cscript% OffScrubC2R.vbs ALL /QUIET /OFFLINE |
||||
%_Nul3% call :vNextDir |
||||
%_Nul3% call :officeREG 16 |
||||
goto :eof |
||||
|
||||
:rOUWP |
||||
echo. |
||||
echo Remove Office UWP Apps |
||||
%_Nul3% %_psc% "Get-AppXPackage -Name '*Microsoft.Office.Desktop*' | Foreach {Remove-AppxPackage $_.PackageFullName}" |
||||
%_Nul3% %_psc% "Get-AppXProvisionedPackage -Online | Where DisplayName -Like '*Microsoft.Office.Desktop*' | Remove-AppXProvisionedPackage -Online" |
||||
goto :eof |
||||
|
||||
:rOM16 |
||||
echo. |
||||
echo Scrub Office 2016 MSI |
||||
call :cKpp 16 |
||||
%_Nul3% %_cscript% OffScrub_O16msi.vbs %_para% |
||||
%_Nul3% call :officeREG 16 |
||||
goto :eof |
||||
|
||||
:rOM15 |
||||
echo. |
||||
echo Scrub Office 2013 MSI |
||||
call :cKpp 15 |
||||
%_Nul3% %_cscript% OffScrub_O15msi.vbs %_para% |
||||
%_Nul3% call :officeREG 15 |
||||
goto :eof |
||||
|
||||
:rOM14 |
||||
echo. |
||||
echo Scrub Office 2010 |
||||
call :cK14 |
||||
%_Nul3% %_cscript% OffScrub10.vbs %_para% |
||||
%_Nul3% call :officeREG 14 |
||||
goto :eof |
||||
|
||||
:rOM12 |
||||
echo. |
||||
echo Scrub Office 2007 |
||||
%_Nul3% %_cscript% OffScrub07.vbs %_para% |
||||
%_Nul3% call :officeREG 12 |
||||
goto :eof |
||||
|
||||
:rOM11 |
||||
echo. |
||||
echo Scrub Office 2003 |
||||
%_Nul3% %_cscript% OffScrub03.vbs %_para% |
||||
%_Nul3% call :officeREG 11 |
||||
goto :eof |
||||
|
||||
:cSPP |
||||
%xBit%\cleanospp.exe %_Nul3% |
||||
call :slmgr |
||||
goto :eof |
||||
|
||||
:slmgr |
||||
if exist "%SysPath%\spp\store_test\2.0\tokens.dat" ( |
||||
echo. |
||||
echo Refresh Windows Insider Preview Licenses |
||||
%_cscript% %SysPath%\slmgr.vbs /rilc %_Nul3% |
||||
if !ERRORLEVEL! NEQ 0 %_cscript% %SysPath%\slmgr.vbs /rilc %_Nul3% |
||||
) |
||||
goto :eof |
||||
|
||||
:Fin |
||||
for /f %%# in ('"dir /b %SystemRoot%\temp\ose*.exe" %_Nul6%') do taskkill /t /f /IM %%# %_Nul3% |
||||
del /f /q "%SystemRoot%\temp\ose*.exe" %_Nul3% |
||||
set "msg=Finished. It's recommended to restart the system." |
||||
goto :TheEnd |
||||
|
||||
:officeMSI |
||||
set _O%1MSI=0 |
||||
for /f "skip=2 tokens=2*" %%a in ('"reg query HKLM\SOFTWARE\Microsoft\Office\%1.0\Common\InstallRoot /v Path" %_Nul6%') do if exist "%%b\*.dll" set _O%1MSI=1 |
||||
if exist "%ProgramFiles%\Microsoft Office\Office%1\*.dll" set _O%1MSI=1 |
||||
if %xOS%==x86 goto :eof |
||||
for /f "skip=2 tokens=2*" %%a in ('"reg query HKLM\SOFTWARE\Wow6432Node\Microsoft\Office\%1.0\Common\InstallRoot /v Path" %_Nul6%') do if exist "%%b\*.dll" set _O%1MSI=1 |
||||
if exist "%ProgramW6432%\Microsoft Office\Office%1\*.dll" set _O%1MSI=1 |
||||
if exist "%ProgramFiles(x86)%\Microsoft Office\Office%1\*.dll" set _O%1MSI=1 |
||||
goto :eof |
||||
|
||||
:officeREG |
||||
reg delete HKCU\Software\Microsoft\Office\%1.0 /f |
||||
reg delete HKCU\Software\Policies\Microsoft\Office\%1.0 /f |
||||
reg delete HKLM\SOFTWARE\Microsoft\Office\%1.0 /f |
||||
reg delete HKLM\SOFTWARE\Policies\Microsoft\Office\%1.0 /f |
||||
reg delete HKLM\SOFTWARE\Microsoft\Office\%1.0 /f /reg:32 |
||||
reg delete HKLM\SOFTWARE\Policies\Microsoft\Office\%1.0 /f /reg:32 |
||||
goto :eof |
||||
|
||||
:cK14 |
||||
if %_WSH% EQU 0 if %WMI_VBS% NEQ 0 goto :eof |
||||
if %WMI_VBS% NEQ 0 cd .. |
||||
set _spp=OfficeSoftwareProtectionProduct |
||||
if %OsppHook% NEQ 0 ( |
||||
call :cKEY 14 |
||||
) |
||||
if %WMI_VBS% NEQ 0 cd bin |
||||
goto :eof |
||||
|
||||
:cKpp |
||||
if %_WSH% EQU 0 if %WMI_VBS% NEQ 0 goto :eof |
||||
if %WMI_VBS% NEQ 0 cd .. |
||||
set _spp=SoftwareLicensingProduct |
||||
if %winbuild% GEQ 9200 ( |
||||
call :cKEY %1 |
||||
) |
||||
set _spp=OfficeSoftwareProtectionProduct |
||||
if %winbuild% LSS 9200 if %OsppHook% NEQ 0 ( |
||||
call :cKEY %1 |
||||
) |
||||
if %WMI_VBS% NEQ 0 cd bin |
||||
goto :eof |
||||
|
||||
:cKMS |
||||
if %_WSH% EQU 0 if %WMI_VBS% NEQ 0 goto :eof |
||||
if %WMI_VBS% NEQ 0 cd .. |
||||
set _spp=SoftwareLicensingProduct |
||||
if %winbuild% GEQ 9200 ( |
||||
reg delete "HKLM\%SPPk%\%_oApp%" /f |
||||
reg delete "HKLM\%SPPk%\%_oApp%" /f /reg:32 |
||||
reg delete "HKEY_USERS\S-1-5-20\%SPPk%\%_oApp%" /f |
||||
for %%A in (15,16,19,21) do call :cKEY %%A |
||||
) |
||||
set _spp=OfficeSoftwareProtectionProduct |
||||
if %winbuild% GEQ 9200 if %OsppHook% NEQ 0 ( |
||||
call :cKEY 14 |
||||
) |
||||
if %winbuild% LSS 9200 if %OsppHook% NEQ 0 ( |
||||
reg delete "HKLM\%OPPk%\%_oApp%" /f |
||||
reg delete "HKLM\%OPPk%\%_oApp%" /f /reg:32 |
||||
for %%A in (14,15,16,19,21) do call :cKEY %%A |
||||
) |
||||
reg delete "HKLM\%OPPk%\%_oA14%" /f |
||||
reg delete "HKEY_USERS\S-1-5-20\%OPPk%" /f |
||||
if %WMI_VBS% NEQ 0 cd bin |
||||
goto :eof |
||||
|
||||
:cKEY |
||||
set "_ocq=Name LIKE 'Office %~1%%' AND PartialProductKey is not NULL" |
||||
set "_qr="wmic path %_spp% where (%_ocq%) get ID /VALUE"" |
||||
if %WMI_VBS% NEQ 0 set "_qr=%_csq% %_spp% "%_ocq%" ID" |
||||
for /f "tokens=2 delims==" %%# in ('%_qr% %_Nul6%') do (set "aID=%%#"&call :cAPP) |
||||
goto :eof |
||||
|
||||
:cAPP |
||||
set "_qr=wmic path %_spp% where ID='%aID%' call UninstallProductKey" |
||||
if %WMI_VBS% NEQ 0 set "_qr=%_csm% "%_spp%.ID='%aID%'" UninstallProductKey" |
||||
%_qr% %_Nul3% |
||||
goto :eof |
||||
|
||||
:vNextDir |
||||
attrib -R "!ProgramData!\Microsoft\Office\Licenses" |
||||
attrib -R "!_Local!\Microsoft\Office\Licenses" |
||||
rd /s /q "!ProgramData!\Microsoft\Office\Licenses\" |
||||
rd /s /q "!_Local!\Microsoft\Office\Licenses\" |
||||
goto :eof |
||||
|
||||
:vNextREG |
||||
reg delete "%kO16%\Common\Licensing" /f |
||||
reg delete "%kO16%\Registration" /f |
||||
goto :eof |
||||
|
||||
:LcnsC |
||||
call :Hdr |
||||
echo. |
||||
echo Clean vNext Licenses |
||||
%_Nul3% call :vNextDir |
||||
%_Nul3% call :vNextREG |
||||
set "msg=Done." |
||||
goto :TheEnd |
||||
|
||||
:KeysU |
||||
call :Hdr |
||||
echo. |
||||
echo Uninstall Product Keys |
||||
%xBit%\cleanospp.exe -PKey %_Nul3% |
||||
for %%A in (15,16,19,21) do call :cKpp %%A |
||||
set "msg=Done." |
||||
goto :TheEnd |
||||
|
||||
:LcnsR |
||||
call :Hdr |
||||
echo. |
||||
echo Remove Office Licenses |
||||
%xBit%\cleanospp.exe -Licenses %_Nul3% |
||||
call :slmgr |
||||
set "msg=Done." |
||||
goto :TheEnd |
||||
|
||||
:LcnsT |
||||
call :Hdr |
||||
echo. |
||||
echo Reset Office C2R Licenses |
||||
if %_O16CTR% equ 0 ( |
||||
set "msg=ERROR: No installed Office ClickToRun detected." |
||||
goto :TheEnd |
||||
) |
||||
set "_InstallRoot=" |
||||
for /f "skip=2 tokens=2*" %%a in ('"reg query HKLM\SOFTWARE\Microsoft\Office\ClickToRun /v InstallPath" %_Nul6%') do (set "_InstallRoot=%%b\root") |
||||
if not "%_InstallRoot%"=="" ( |
||||
for /f "skip=2 tokens=2*" %%a in ('"reg query HKLM\SOFTWARE\Microsoft\Office\ClickToRun /v PackageGUID" %_Nul6%') do (set "_GUID=%%b") |
||||
set "_PRIDs=HKLM\SOFTWARE\Microsoft\Office\ClickToRun\ProductReleaseIDs" |
||||
) else ( |
||||
for /f "skip=2 tokens=2*" %%a in ('"reg query HKLM\SOFTWARE\WOW6432Node\Microsoft\Office\ClickToRun /v InstallPath" %_Nul6%') do (set "_InstallRoot=%%b\root") |
||||
for /f "skip=2 tokens=2*" %%a in ('"reg query HKLM\SOFTWARE\WOW6432Node\Microsoft\Office\ClickToRun /v PackageGUID" %_Nul6%') do (set "_GUID=%%b") |
||||
set "_PRIDs=HKLM\SOFTWARE\WOW6432Node\Microsoft\Office\ClickToRun\ProductReleaseIDs" |
||||
) |
||||
set "_Integrator=%_InstallRoot%\integration\integrator.exe" |
||||
for /f "skip=2 tokens=2*" %%a in ('"reg query %_PRIDs% /v ActiveConfiguration" %_Nul6%') do set "_PRIDs=%_PRIDs%\%%b" |
||||
if not exist "%_Integrator%" ( |
||||
set "msg=ERROR: Could not detect Office Licenses Integrator.exe" |
||||
goto :TheEnd |
||||
) |
||||
for /f "tokens=8 delims=\" %%a in ('reg query "%_PRIDs%" /f ".16" /k %_Nul6% ^| find /i "ClickToRun"') do ( |
||||
if not defined _SKUs (set "_SKUs=%%a") else (set "_SKUs=!_SKUs!,%%a") |
||||
) |
||||
if not defined _SKUs ( |
||||
set "msg=ERROR: Could not detect originally installed Office Products." |
||||
goto :TheEnd |
||||
) |
||||
echo. |
||||
echo Remove Office Licenses |
||||
%xBit%\cleanospp.exe -Licenses %_Nul3% |
||||
call :slmgr |
||||
echo. |
||||
echo Install Office C2R Licenses |
||||
for %%a in (%_SKUs%) do ( |
||||
"!_Integrator!" /R /License PRIDName=%%a.16 PackageGUID="%_GUID%" PackageRoot="!_InstallRoot!" %_Nul1% |
||||
) |
||||
set "msg=Done." |
||||
goto :TheEnd |
||||
|
||||
:E_Admin |
||||
set "msg=ERROR: This script requires administrator privileges." |
||||
goto :TheEnd |
||||
|
||||
:TheEnd |
||||
echo. |
||||
echo ============================================================ |
||||
echo %msg% |
||||
echo. |
||||
echo Press any key to exit. |
||||
pause >nul |
||||
goto :eof |
||||
|
||||
----- Begin wsf script ---> |
||||
<package> |
||||
<job id="WmiQuery"> |
||||
<script language="VBScript"> |
||||
If WScript.Arguments.Count = 3 Then |
||||
wExc = "Select " & WScript.Arguments.Item(2) & " from " & WScript.Arguments.Item(0) & " where " & WScript.Arguments.Item(1) |
||||
wGet = WScript.Arguments.Item(2) |
||||
Else |
||||
wExc = "Select " & WScript.Arguments.Item(1) & " from " & WScript.Arguments.Item(0) |
||||
wGet = WScript.Arguments.Item(1) |
||||
End If |
||||
Set objCol = GetObject("winmgmts:\\.\root\CIMV2").ExecQuery(wExc,,48) |
||||
For Each objItm in objCol |
||||
For each Prop in objItm.Properties_ |
||||
If LCase(Prop.Name) = LCase(wGet) Then |
||||
WScript.Echo Prop.Name & "=" & Prop.Value |
||||
Exit For |
||||
End If |
||||
Next |
||||
Next |
||||
</script> |
||||
</job> |
||||
<job id="WmiMethod"> |
||||
<script language="VBScript"> |
||||
On Error Resume Next |
||||
wPath = WScript.Arguments.Item(0) |
||||
wMethod = WScript.Arguments.Item(1) |
||||
Set objCol = GetObject("winmgmts:\\.\root\CIMV2:" & wPath) |
||||
objCol.ExecMethod_(wMethod) |
||||
WScript.Quit Err.Number |
||||
</script> |
||||
</job> |
||||
<job id="ELAV"> |
||||
<script language="VBScript"> |
||||
Set strArg=WScript.Arguments.Named |
||||
Set strRdlproc = CreateObject("WScript.Shell").Exec("rundll32 kernel32,Sleep") |
||||
With GetObject("winmgmts:\\.\root\CIMV2:Win32_Process.Handle='" & strRdlproc.ProcessId & "'") |
||||
With GetObject("winmgmts:\\.\root\CIMV2:Win32_Process.Handle='" & .ParentProcessId & "'") |
||||
If InStr (.CommandLine, WScript.ScriptName) <> 0 Then |
||||
strLine = Mid(.CommandLine, InStr(.CommandLine , "/File:") + Len(strArg("File")) + 8) |
||||
End If |
||||
End With |
||||
.Terminate |
||||
End With |
||||
CreateObject("Shell.Application").ShellExecute "cmd.exe", "/c " & chr(34) & chr(34) & strArg("File") & chr(34) & strLine & chr(34), "", "runas", 1 |
||||
</script> |
||||
</job> |
||||
</package> |
@ -1,34 +1,84 @@
@@ -1,34 +1,84 @@
|
||||
# Office Scrubber |
||||
|
||||
* An automated scripts to uninstall, remove and scrub Office 2016 MSI and Office Click-to-Run 16.0 |
||||
* An automated script to uninstall, remove and scrub Microsoft Office (MSI or Click-to-Run) |
||||
|
||||
* It mostly execute OffScrub vbs scripts, obtained from SaRA tool (Microsoft Support and Recovery Assistant) |
||||
|
||||
* Office (2021, 2019, 2016, 365) all share the same installation location and licensing level, which may lead to licenses confliction or duplication |
||||
|
||||
* Additionally, if you uninstalled Office normally on Windows 8/8.1/10, the licenses will be left installed in the system SPP token store |
||||
Additionally, if you uninstalled Office 2013+ normally on Windows 8 or later, the licenses will be left installed in the system SPP token store |
||||
|
||||
## Scrub ALL Overview |
||||
|
||||
* By default, this operation will remove the detected Office versions only |
||||
in addition to uninstalling product keys, and clean licenses leftovers |
||||
|
||||
* However, you can use the numbers 2-8 to toggle the state for menu options |
||||
and force to scrub or skip that Office version |
||||
|
||||
* It's recommended to only scrub the detected versions {*} |
||||
selecting all is not necessary and will take a long time. |
||||
|
||||
## Main Options Overview |
||||
|
||||
* Scrub ALL |
||||
|
||||
uninstall and remove one or more Office versions |
||||
|
||||
* Scrub Office C2R |
||||
|
||||
uninstall and remove Office Click-to-Run (365, 2021, LTSC, 2019, 2016, 2013) |
||||
the operation will be executed regardless if this Office is detected or not |
||||
|
||||
* Scrub Office 2016 |
||||
|
||||
uninstall and remove Office 2016 MSI version |
||||
the operation will be executed regardless if this Office is detected or not |
||||
|
||||
* Scrub Office 2013 |
||||
|
||||
## Usage: |
||||
uninstall and remove Office 2013 MSI version |
||||
the operation will be executed regardless if this Office is detected or not |
||||
|
||||
* Full_Scrub.cmd |
||||
completely uninstall and remove Office |
||||
* Scrub Office 2010 |
||||
|
||||
* Uninstall_Keys.cmd |
||||
uninstall Office product keys (in case of confliction) |
||||
uninstall and remove Office 2010 MSI or C2R version |
||||
the operation will be executed regardless if this Office is detected or not |
||||
|
||||
* Remove_Licenses.cmd |
||||
clean Office licenses (in case of confliction) |
||||
* Scrub Office 2007 |
||||
|
||||
you can then repair Office to restore original licenses, or use C2R-R2V to install proper licenses |
||||
uninstall and remove Office 2007 |
||||
the operation will be executed regardless if this Office is detected or not |
||||
|
||||
* Reset_Licenses.cmd |
||||
clean Office licenses, and then reinstall original licenses |
||||
* Scrub Office 2003 |
||||
|
||||
uninstall and remove Office 2003 |
||||
the operation will be executed regardless if this Office is detected or not |
||||
|
||||
* Scrub Office UWP |
||||
|
||||
uninstall and remove Office Store Apps on Windows 11/10 |
||||
the operation will be executed regardless if this Office is detected or not |
||||
|
||||
## Extra Options Overview |
||||
|
||||
* Clean vNext Licenses |
||||
|
||||
remove Office vNext licenses (subscription or lifetime), tokens and cached identities |
||||
|
||||
* Remove all Licenses |
||||
|
||||
remove licenses for Office 2013 and later (in case of confliction) |
||||
|
||||
you can then repair Office to restore original licenses, or use C2R-R2V to install Office C2R licenses |
||||
|
||||
* Reset C2R Licenses |
||||
|
||||
remove licenses for Office 2016 and later, and then reinstall original Office C2R licenses |
||||
|
||||
you can use this in case Office repair failed to restore original licenses, |
||||
or to remove C2R-R2V Volume licenses and restore original Retail licenses |
||||
|
||||
* Clean_Subscription_Licenses.cmd |
||||
clean Office subscription licenses, credentials, tokens and cached identities |
||||
|
||||
it simply execute OLicenseCleanup.vbs |
||||
https://docs.microsoft.com/en-us/office/troubleshoot/activation/reset-office-365-proplus-activation-state |
||||
* Uninstall all Keys |
||||
|
||||
for Windows 10 version 1803 or later, it also execute WAMAccounts.ps1 (SignOutOfWAMAccounts.ps1) |
||||
uninstall product keys for Office 2013 and later (in case of confliction) |
||||
|
@ -1,126 +0,0 @@
@@ -1,126 +0,0 @@
|
||||
@setlocal DisableDelayedExpansion |
||||
@echo off |
||||
set _args= |
||||
set _args=%* |
||||
if not defined _args goto :NoProgArgs |
||||
for %%A in (%_args%) do ( |
||||
if /i "%%A"=="-wow" set _rel1=1 |
||||
if /i "%%A"=="-arm" set _rel2=1 |
||||
) |
||||
:NoProgArgs |
||||
set "_cmdf=%~f0" |
||||
if exist "%SystemRoot%\Sysnative\cmd.exe" if not defined _rel1 ( |
||||
setlocal EnableDelayedExpansion |
||||
start %SystemRoot%\Sysnative\cmd.exe /c ""!_cmdf!" -wow" |
||||
exit /b |
||||
) |
||||
if exist "%SystemRoot%\SysArm32\cmd.exe" if /i %PROCESSOR_ARCHITECTURE%==AMD64 if not defined _rel2 ( |
||||
setlocal EnableDelayedExpansion |
||||
start %SystemRoot%\SysArm32\cmd.exe /c ""!_cmdf!" -arm" |
||||
exit /b |
||||
) |
||||
set "SysPath=%SystemRoot%\System32" |
||||
if exist "%SystemRoot%\Sysnative\reg.exe" (set "SysPath=%SystemRoot%\Sysnative") |
||||
set "Path=%SysPath%;%SystemRoot%;%SysPath%\Wbem;%SysPath%\WindowsPowerShell\v1.0\" |
||||
reg query HKU\S-1-5-19 >nul 2>&1 || ( |
||||
set "msg=ERROR: right click on the script and 'Run as administrator'" |
||||
goto :end |
||||
) |
||||
for /f "tokens=6 delims=[]. " %%G in ('ver') do set winbuild=%%G |
||||
if %winbuild% LSS 7601 ( |
||||
set "msg=ERROR: Windows 7 SP1 is the minimum supported OS" |
||||
goto :end |
||||
) |
||||
set "_Common=%CommonProgramFiles%" |
||||
if defined PROCESSOR_ARCHITEW6432 set "_Common=%CommonProgramW6432%" |
||||
if /i "%PROCESSOR_ARCHITECTURE%"=="amd64" set "xBit=x64" |
||||
if /i "%PROCESSOR_ARCHITECTURE%"=="arm64" set "xBit=x86" |
||||
if /i "%PROCESSOR_ARCHITECTURE%"=="x86" if "%PROCESSOR_ARCHITEW6432%"=="" set "xBit=x86" |
||||
if /i "%PROCESSOR_ARCHITEW6432%"=="amd64" set "xBit=x64" |
||||
if /i "%PROCESSOR_ARCHITEW6432%"=="arm64" set "xBit=x86" |
||||
set "_file=%_Common%\Microsoft Shared\ClickToRun\OfficeClickToRun.exe" |
||||
set "_fil2=%CommonProgramFiles(x86)%\Microsoft Shared\ClickToRun\OfficeClickToRun.exe" |
||||
set "_work=%~dp0bin" |
||||
setlocal EnableDelayedExpansion |
||||
pushd "!_work!" |
||||
if not exist "%xBit%\cleanospp.exe" ( |
||||
set "msg=ERROR: required file cleanospp.exe is missing" |
||||
goto :end |
||||
) |
||||
set "_Nul1=1>nul" |
||||
set "_Nul2=2>nul" |
||||
set "_Nul6=2^>nul" |
||||
set "_Nul3=1>nul 2>nul" |
||||
|
||||
title Remove Office Licenses |
||||
set OfficeC2R=0 |
||||
sc query ClickToRunSvc %_Nul3% && set OfficeC2R=1 |
||||
sc query OfficeSvc %_Nul3% && set OfficeC2R=1 |
||||
reg query HKLM\SOFTWARE\Microsoft\Office\ClickToRun\Configuration /v ProductReleaseIds %_Nul3% && ( |
||||
set OfficeC2R=1 |
||||
) |
||||
reg query HKLM\SOFTWARE\WOW6432Node\Microsoft\Office\ClickToRun\Configuration /v ProductReleaseIds %_Nul3% && ( |
||||
set OfficeC2R=1 |
||||
) |
||||
if exist "!_file!" set OfficeC2R=1 |
||||
if exist "!_fil2!" if /i "%PROCESSOR_ARCHITECTURE%"=="arm64" set OfficeC2R=1 |
||||
set OfficeMSI=0 |
||||
for /f "skip=2 tokens=2*" %%a in ('"reg query HKLM\SOFTWARE\Microsoft\Office\16.0\Common\InstallRoot /v Path" %_Nul6%') do if exist "%%b\OSPP.VBS" set OfficeMSI=1 |
||||
for /f "skip=2 tokens=2*" %%a in ('"reg query HKLM\SOFTWARE\Wow6432Node\Microsoft\Office\16.0\Common\InstallRoot /v Path" %_Nul6%') do if exist "%%b\OSPP.VBS" set OfficeMSI=1 |
||||
set OfficeUWP=0 |
||||
if %winbuild% GEQ 10240 reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\msoxmled.exe" %_Nul3% && ( |
||||
dir /b "%ProgramFiles%\WindowsApps\Microsoft.Office.Desktop*" %_Nul3% && set OfficeUWP=1 |
||||
dir /b "%ProgramW6432%\WindowsApps\Microsoft.Office.Desktop*" %_Nul3% && set OfficeUWP=1 |
||||
dir /b "%ProgramFiles(x86)%\WindowsApps\Microsoft.Office.Desktop*" %_Nul3% && set OfficeUWP=1 |
||||
) |
||||
|
||||
if %OfficeC2R% equ 0 if %OfficeMSI% equ 0 if %OfficeUWP% equ 0 ( |
||||
echo. |
||||
echo ============================================================ |
||||
echo No installed Office ClickToRun or Office 2016 MSI detected |
||||
echo. |
||||
echo. |
||||
choice /C YN /N /M "Continue with removing Office licenses anyway? [y/n]: " |
||||
if errorlevel 2 goto :eof |
||||
if errorlevel 1 goto :main |
||||
) |
||||
echo. |
||||
echo ============================================================ |
||||
if %OfficeC2R% equ 1 echo Detected Office C2R |
||||
if %OfficeMSI% equ 1 echo Detected Office 2016 MSI |
||||
if %OfficeUWP% equ 1 echo Detected Office UWP Apps |
||||
echo. |
||||
echo. |
||||
choice /C YN /N /M "Continue with removing detected Office licenses? [y/n]: " |
||||
if errorlevel 2 goto :eof |
||||
if errorlevel 1 goto :main |
||||
|
||||
:main |
||||
cls |
||||
echo. |
||||
echo ============================================================ |
||||
echo Cleaning Office Licenses... |
||||
echo ============================================================ |
||||
echo. |
||||
%xBit%\cleanospp.exe -Licenses %_Nul3% |
||||
if exist "%SysPath%\spp\store_test\2.0\tokens.dat" ( |
||||
echo. |
||||
echo ============================================================ |
||||
echo Refreshing Windows Insider Preview Licenses... |
||||
echo ============================================================ |
||||
echo. |
||||
cscript //Nologo //B %SysPath%\slmgr.vbs /rilc |
||||
if !ERRORLEVEL! NEQ 0 cscript //Nologo //B %SysPath%\slmgr.vbs /rilc |
||||
) |
||||
set "msg=Finished." |
||||
goto :end |
||||
|
||||
:end |
||||
echo. |
||||
echo ============================================================ |
||||
echo %msg% |
||||
echo ============================================================ |
||||
echo. |
||||
echo Press any key to exit. |
||||
pause >nul |
||||
goto :eof |
@ -1,130 +0,0 @@
@@ -1,130 +0,0 @@
|
||||
@setlocal DisableDelayedExpansion |
||||
@echo off |
||||
set _args= |
||||
set _args=%* |
||||
if not defined _args goto :NoProgArgs |
||||
for %%A in (%_args%) do ( |
||||
if /i "%%A"=="-wow" set _rel1=1 |
||||
if /i "%%A"=="-arm" set _rel2=1 |
||||
) |
||||
:NoProgArgs |
||||
set "_cmdf=%~f0" |
||||
if exist "%SystemRoot%\Sysnative\cmd.exe" if not defined _rel1 ( |
||||
setlocal EnableDelayedExpansion |
||||
start %SystemRoot%\Sysnative\cmd.exe /c ""!_cmdf!" -wow" |
||||
exit /b |
||||
) |
||||
if exist "%SystemRoot%\SysArm32\cmd.exe" if /i %PROCESSOR_ARCHITECTURE%==AMD64 if not defined _rel2 ( |
||||
setlocal EnableDelayedExpansion |
||||
start %SystemRoot%\SysArm32\cmd.exe /c ""!_cmdf!" -arm" |
||||
exit /b |
||||
) |
||||
set "SysPath=%SystemRoot%\System32" |
||||
if exist "%SystemRoot%\Sysnative\reg.exe" (set "SysPath=%SystemRoot%\Sysnative") |
||||
set "Path=%SysPath%;%SystemRoot%;%SysPath%\Wbem;%SysPath%\WindowsPowerShell\v1.0\" |
||||
reg query HKU\S-1-5-19 >nul 2>&1 || ( |
||||
set "msg=ERROR: right click on the script and 'Run as administrator'" |
||||
goto :end |
||||
) |
||||
for /f "tokens=6 delims=[]. " %%G in ('ver') do set winbuild=%%G |
||||
if %winbuild% LSS 7601 ( |
||||
set "msg=ERROR: Windows 7 SP1 is the minimum supported OS" |
||||
goto :end |
||||
) |
||||
set "_Common=%CommonProgramFiles%" |
||||
if defined PROCESSOR_ARCHITEW6432 set "_Common=%CommonProgramW6432%" |
||||
if /i "%PROCESSOR_ARCHITECTURE%"=="amd64" set "xBit=x64" |
||||
if /i "%PROCESSOR_ARCHITECTURE%"=="arm64" set "xBit=x86" |
||||
if /i "%PROCESSOR_ARCHITECTURE%"=="x86" if "%PROCESSOR_ARCHITEW6432%"=="" set "xBit=x86" |
||||
if /i "%PROCESSOR_ARCHITEW6432%"=="amd64" set "xBit=x64" |
||||
if /i "%PROCESSOR_ARCHITEW6432%"=="arm64" set "xBit=x86" |
||||
set "_file=%_Common%\Microsoft Shared\ClickToRun\OfficeClickToRun.exe" |
||||
set "_fil2=%CommonProgramFiles(x86)%\Microsoft Shared\ClickToRun\OfficeClickToRun.exe" |
||||
set "_work=%~dp0bin" |
||||
setlocal EnableDelayedExpansion |
||||
pushd "!_work!" |
||||
if not exist "%xBit%\cleanospp.exe" ( |
||||
set "msg=ERROR: required file cleanospp.exe is missing" |
||||
goto :end |
||||
) |
||||
set "_Nul1=1>nul" |
||||
set "_Nul2=2>nul" |
||||
set "_Nul6=2^>nul" |
||||
set "_Nul3=1>nul 2>nul" |
||||
|
||||
title Reset Office C2R Licenses |
||||
set OfficeC2R=0 |
||||
for /f "skip=2 tokens=2*" %%a in ('"reg query HKLM\SOFTWARE\Microsoft\Office\ClickToRun /v InstallPath" %_Nul6%') do if exist "%%b\root\Licenses16\ProPlus*.xrm-ms" set OfficeC2R=1 |
||||
if %OfficeC2R% equ 0 for /f "skip=2 tokens=2*" %%a in ('"reg query HKLM\SOFTWARE\WOW6432Node\Microsoft\Office\ClickToRun /v InstallPath" %_Nul6%') do if exist "%%b\root\Licenses16\ProPlus*.xrm-ms" set OfficeC2R=1 |
||||
if exist "!_file!" set OfficeC2R=1 |
||||
if exist "!_fil2!" if /i "%PROCESSOR_ARCHITECTURE%"=="arm64" set OfficeC2R=1 |
||||
if %OfficeC2R% equ 0 ( |
||||
set "msg=No installed Office ClickToRun detected" |
||||
goto :end |
||||
) |
||||
|
||||
:main |
||||
set "_InstallRoot=" |
||||
set "_ProductIds=" |
||||
for /f "skip=2 tokens=2*" %%a in ('"reg query HKLM\SOFTWARE\Microsoft\Office\ClickToRun /v InstallPath" %_Nul6%') do (set "_InstallRoot=%%b\root") |
||||
if not "%_InstallRoot%"=="" ( |
||||
for /f "skip=2 tokens=2*" %%a in ('"reg query HKLM\SOFTWARE\Microsoft\Office\ClickToRun /v PackageGUID" %_Nul6%') do (set "_GUID=%%b") |
||||
for /f "skip=2 tokens=2*" %%a in ('"reg query HKLM\SOFTWARE\Microsoft\Office\ClickToRun\Configuration /v ProductReleaseIds" %_Nul6%') do (set "_ProductIds=%%b") |
||||
set "_Config=HKLM\SOFTWARE\Microsoft\Office\ClickToRun\Configuration" |
||||
set "_PRIDs=HKLM\SOFTWARE\Microsoft\Office\ClickToRun\ProductReleaseIDs" |
||||
) else ( |
||||
for /f "skip=2 tokens=2*" %%a in ('"reg query HKLM\SOFTWARE\WOW6432Node\Microsoft\Office\ClickToRun /v InstallPath" %_Nul6%') do (set "_InstallRoot=%%b\root") |
||||
for /f "skip=2 tokens=2*" %%a in ('"reg query HKLM\SOFTWARE\WOW6432Node\Microsoft\Office\ClickToRun /v PackageGUID" %_Nul6%') do (set "_GUID=%%b") |
||||
for /f "skip=2 tokens=2*" %%a in ('"reg query HKLM\SOFTWARE\WOW6432Node\Microsoft\Office\ClickToRun\Configuration /v ProductReleaseIds" %_Nul6%') do (set "_ProductIds=%%b") |
||||
set "_Config=HKLM\SOFTWARE\WOW6432Node\Microsoft\Office\ClickToRun\Configuration" |
||||
set "_PRIDs=HKLM\SOFTWARE\WOW6432Node\Microsoft\Office\ClickToRun\ProductReleaseIDs" |
||||
) |
||||
set "_Integrator=%_InstallRoot%\integration\integrator.exe" |
||||
for /f "skip=2 tokens=2*" %%a in ('"reg query %_PRIDs% /v ActiveConfiguration" %_Nul6%') do set "_PRIDs=%_PRIDs%\%%b" |
||||
if not exist "%_Integrator%" ( |
||||
set "msg=ERROR: Could not detect Office Licenses Integrator.exe" |
||||
goto :end |
||||
) |
||||
for /f "tokens=8 delims=\" %%a in ('reg query "%_PRIDs%" /f ".16" /k %_Nul6% ^| find /i "ClickToRun"') do ( |
||||
if not defined _SKUs (set "_SKUs=%%a") else (set "_SKUs=!_SKUs!,%%a") |
||||
) |
||||
if not defined _SKUs ( |
||||
set "msg=ERROR: Could not detect originally installed Office Products" |
||||
goto :end |
||||
) |
||||
cls |
||||
echo. |
||||
echo ============================================================ |
||||
echo Cleaning Office Licenses... |
||||
echo ============================================================ |
||||
echo. |
||||
%xBit%\cleanospp.exe -Licenses %_Nul3% |
||||
if exist "%SysPath%\spp\store_test\2.0\tokens.dat" ( |
||||
echo. |
||||
echo ============================================================ |
||||
echo Refreshing Windows Insider Preview Licenses... |
||||
echo ============================================================ |
||||
echo. |
||||
cscript //Nologo //B %SysPath%\slmgr.vbs /rilc |
||||
if !ERRORLEVEL! NEQ 0 cscript //Nologo //B %SysPath%\slmgr.vbs /rilc |
||||
) |
||||
echo. |
||||
echo ============================================================ |
||||
echo Installing Office C2R Licenses... |
||||
echo ============================================================ |
||||
echo. |
||||
for %%a in (%_SKUs%) do ( |
||||
"!_Integrator!" /R /License PRIDName=%%a.16 PackageGUID="%_GUID%" PackageRoot="!_InstallRoot!" %_Nul1% |
||||
) |
||||
set "msg=Finished." |
||||
goto :end |
||||
|
||||
:end |
||||
echo. |
||||
echo ============================================================ |
||||
echo %msg% |
||||
echo ============================================================ |
||||
echo. |
||||
echo Press any key to exit. |
||||
pause >nul |
||||
goto :eof |
@ -1,208 +0,0 @@
@@ -1,208 +0,0 @@
|
||||
<!-- : Begin batch script |
||||
@setlocal DisableDelayedExpansion |
||||
@echo off |
||||
set _args= |
||||
set _args=%* |
||||
if not defined _args goto :NoProgArgs |
||||
for %%A in (%_args%) do ( |
||||
if /i "%%A"=="-wow" set _rel1=1 |
||||
if /i "%%A"=="-arm" set _rel2=1 |
||||
) |
||||
:NoProgArgs |
||||
set "_cmdf=%~f0" |
||||
if exist "%SystemRoot%\Sysnative\cmd.exe" if not defined _rel1 ( |
||||
setlocal EnableDelayedExpansion |
||||
start %SystemRoot%\Sysnative\cmd.exe /c ""!_cmdf!" -wow" |
||||
exit /b |
||||
) |
||||
if exist "%SystemRoot%\SysArm32\cmd.exe" if /i %PROCESSOR_ARCHITECTURE%==AMD64 if not defined _rel2 ( |
||||
setlocal EnableDelayedExpansion |
||||
start %SystemRoot%\SysArm32\cmd.exe /c ""!_cmdf!" -arm" |
||||
exit /b |
||||
) |
||||
set "SysPath=%SystemRoot%\System32" |
||||
if exist "%SystemRoot%\Sysnative\reg.exe" (set "SysPath=%SystemRoot%\Sysnative") |
||||
set "Path=%SysPath%;%SystemRoot%;%SysPath%\Wbem;%SysPath%\WindowsPowerShell\v1.0\" |
||||
reg query HKU\S-1-5-19 >nul 2>&1 || ( |
||||
set "msg=ERROR: right click on the script and 'Run as administrator'" |
||||
goto :end |
||||
) |
||||
for /f "tokens=6 delims=[]. " %%G in ('ver') do set winbuild=%%G |
||||
if %winbuild% LSS 7601 ( |
||||
set "msg=ERROR: Windows 7 SP1 is the minimum supported OS" |
||||
goto :end |
||||
) |
||||
set _cwmi=0 |
||||
for %%# in (wmic.exe) do @if not "%%~$PATH:#"=="" ( |
||||
wmic path Win32_ComputerSystem get CreationClassName /value 2>nul | find /i "ComputerSystem" 1>nul && set _cwmi=1 |
||||
) |
||||
set "_csq=cscript.exe //NoLogo //Job:WmiQuery "%~nx0?.wsf"" |
||||
set "_csm=cscript.exe //NoLogo //Job:WmiMethod "%~nx0?.wsf"" |
||||
set WMI_VBS=0 |
||||
if %_cwmi% EQU 0 set WMI_VBS=1 |
||||
set _WSH=1 |
||||
reg query "HKCU\SOFTWARE\Microsoft\Windows Script Host\Settings" /v Enabled 2>nul | find /i "0x0" 1>nul && (set _WSH=0) |
||||
reg query "HKLM\SOFTWARE\Microsoft\Windows Script Host\Settings" /v Enabled 2>nul | find /i "0x0" 1>nul && (set _WSH=0) |
||||
set "_oApp=0ff1ce15-a989-479d-af46-f275c6370663" |
||||
set "_oA14=59a52881-a989-479d-af46-f275c6370663" |
||||
set "_Common=%CommonProgramFiles%" |
||||
if defined PROCESSOR_ARCHITEW6432 set "_Common=%CommonProgramW6432%" |
||||
if /i "%PROCESSOR_ARCHITECTURE%"=="amd64" set "xBit=x64" |
||||
if /i "%PROCESSOR_ARCHITECTURE%"=="arm64" set "xBit=x86" |
||||
if /i "%PROCESSOR_ARCHITECTURE%"=="x86" if "%PROCESSOR_ARCHITEW6432%"=="" set "xBit=x86" |
||||
if /i "%PROCESSOR_ARCHITEW6432%"=="amd64" set "xBit=x64" |
||||
if /i "%PROCESSOR_ARCHITEW6432%"=="arm64" set "xBit=x86" |
||||
set "_file=%_Common%\Microsoft Shared\ClickToRun\OfficeClickToRun.exe" |
||||
set "_fil2=%CommonProgramFiles(x86)%\Microsoft Shared\ClickToRun\OfficeClickToRun.exe" |
||||
set "_work=%~dp0bin" |
||||
setlocal EnableDelayedExpansion |
||||
pushd "!_work!" |
||||
if not exist "%xBit%\cleanospp.exe" ( |
||||
set "msg=ERROR: required file cleanospp.exe is missing" |
||||
goto :end |
||||
) |
||||
set "_Nul1=1>nul" |
||||
set "_Nul2=2>nul" |
||||
set "_Nul6=2^>nul" |
||||
set "_Nul3=1>nul 2>nul" |
||||
|
||||
title Uninstall Office Keys |
||||
set OfficeC2R=0 |
||||
sc query ClickToRunSvc %_Nul3% && set OfficeC2R=1 |
||||
sc query OfficeSvc %_Nul3% && set OfficeC2R=1 |
||||
reg query HKLM\SOFTWARE\Microsoft\Office\ClickToRun\Configuration /v ProductReleaseIds %_Nul3% && ( |
||||
set OfficeC2R=1 |
||||
) |
||||
reg query HKLM\SOFTWARE\WOW6432Node\Microsoft\Office\ClickToRun\Configuration /v ProductReleaseIds %_Nul3% && ( |
||||
set OfficeC2R=1 |
||||
) |
||||
if exist "!_file!" set OfficeC2R=1 |
||||
if exist "!_fil2!" if /i "%PROCESSOR_ARCHITECTURE%"=="arm64" set OfficeC2R=1 |
||||
set OfficeMSI=0 |
||||
for /f "skip=2 tokens=2*" %%a in ('"reg query HKLM\SOFTWARE\Microsoft\Office\16.0\Common\InstallRoot /v Path" %_Nul6%') do if exist "%%b\OSPP.VBS" set OfficeMSI=1 |
||||
for /f "skip=2 tokens=2*" %%a in ('"reg query HKLM\SOFTWARE\Wow6432Node\Microsoft\Office\16.0\Common\InstallRoot /v Path" %_Nul6%') do if exist "%%b\OSPP.VBS" set OfficeMSI=1 |
||||
set OfficeUWP=0 |
||||
if %winbuild% GEQ 10240 reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\msoxmled.exe" %_Nul3% && ( |
||||
dir /b "%ProgramFiles%\WindowsApps\Microsoft.Office.Desktop*" %_Nul3% && set OfficeUWP=1 |
||||
dir /b "%ProgramW6432%\WindowsApps\Microsoft.Office.Desktop*" %_Nul3% && set OfficeUWP=1 |
||||
dir /b "%ProgramFiles(x86)%\WindowsApps\Microsoft.Office.Desktop*" %_Nul3% && set OfficeUWP=1 |
||||
) |
||||
|
||||
if %OfficeC2R% equ 0 if %OfficeMSI% equ 0 if %OfficeUWP% equ 0 ( |
||||
echo. |
||||
echo ============================================================ |
||||
echo No installed Office ClickToRun or Office 2016 MSI detected |
||||
echo. |
||||
echo. |
||||
choice /C YN /N /M "Continue with uninstalling Office keys anyway? [y/n]: " |
||||
if errorlevel 2 goto :eof |
||||
if errorlevel 1 goto :main |
||||
) |
||||
echo. |
||||
echo ============================================================ |
||||
if %OfficeC2R% equ 1 echo Detected Office C2R |
||||
if %OfficeMSI% equ 1 echo Detected Office 2016 MSI |
||||
if %OfficeUWP% equ 1 echo Detected Office UWP Apps |
||||
echo. |
||||
echo. |
||||
choice /C YN /N /M "Continue with uninstalling detected Office keys? [y/n]: " |
||||
if errorlevel 2 goto :eof |
||||
if errorlevel 1 goto :main |
||||
|
||||
:main |
||||
cls |
||||
echo. |
||||
echo ============================================================ |
||||
echo Uninstalling Product Key^(s) |
||||
echo ============================================================ |
||||
echo. |
||||
%xBit%\cleanospp.exe -PKey %_Nul3% |
||||
call :cKMS %_Nul3% |
||||
if %WMI_VBS% NEQ 0 cd bin |
||||
if exist "%SysPath%\spp\store_test\2.0\tokens.dat" ( |
||||
echo. |
||||
echo ============================================================ |
||||
echo Refreshing Windows Insider Preview Licenses... |
||||
echo ============================================================ |
||||
echo. |
||||
cscript //Nologo //B %SysPath%\slmgr.vbs /rilc |
||||
if !ERRORLEVEL! NEQ 0 cscript //Nologo //B %SysPath%\slmgr.vbs /rilc |
||||
) |
||||
set "msg=Finished." |
||||
goto :end |
||||
|
||||
:cKMS |
||||
set "OPPk=SOFTWARE\Microsoft\OfficeSoftwareProtectionPlatform" |
||||
set "SPPk=SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform" |
||||
if %winbuild% geq 9200 ( |
||||
set spp=SoftwareLicensingProduct |
||||
reg delete "HKLM\%SPPk%\0ff1ce15-a989-479d-af46-f275c6370663" /f |
||||
reg delete "HKEY_USERS\S-1-5-20\%SPPk%\0ff1ce15-a989-479d-af46-f275c6370663" /f |
||||
) else ( |
||||
set spp=OfficeSoftwareProtectionProduct |
||||
reg delete "HKLM\%OPPk%\0ff1ce15-a989-479d-af46-f275c6370663" /f |
||||
reg delete "HKEY_USERS\S-1-5-20\%OPPk%" /f |
||||
) |
||||
if %_WSH% EQU 0 if %WMI_VBS% NEQ 0 goto :eof |
||||
if %WMI_VBS% NEQ 0 cd .. |
||||
set "_ocq=Name LIKE 'Office%%' AND PartialProductKey is not NULL" |
||||
set "_qr="wmic path %spp% where (%_ocq%) get ID /VALUE"" |
||||
if %WMI_VBS% NEQ 0 set "_qr=%_csq% %spp% "%_ocq%" ID" |
||||
for /f "tokens=2 delims==" %%G in ('%_qr% %_Nul6%') do (set app=%%G&call :cAPP %_Nul3%) |
||||
goto :eof |
||||
|
||||
:cAPP |
||||
if %winbuild% geq 9200 ( |
||||
reg delete "HKLM\%SPPk%\%_oApp%\%app%" /f %_Null% |
||||
) else ( |
||||
reg delete "HKLM\%OPPk%\%_oA14%\%app%" /f %_Null% |
||||
reg delete "HKLM\%OPPk%\%_oApp%\%app%" /f %_Null% |
||||
) |
||||
set "_qr=wmic path %spp% where ID='%app%' call UninstallProductKey" |
||||
if %WMI_VBS% NEQ 0 set "_qr=%_csm% "%spp%.ID='%app%'" UninstallProductKey" |
||||
%_qr% |
||||
goto :eof |
||||
|
||||
:end |
||||
echo. |
||||
echo ============================================================ |
||||
echo %msg% |
||||
echo ============================================================ |
||||
echo. |
||||
echo Press any key to exit. |
||||
pause >nul |
||||
goto :eof |
||||
|
||||
----- Begin wsf script ---> |
||||
<package> |
||||
<job id="WmiQuery"> |
||||
<script language="VBScript"> |
||||
If WScript.Arguments.Count = 3 Then |
||||
wExc = "Select " & WScript.Arguments.Item(2) & " from " & WScript.Arguments.Item(0) & " where " & WScript.Arguments.Item(1) |
||||
wGet = WScript.Arguments.Item(2) |
||||
Else |
||||
wExc = "Select " & WScript.Arguments.Item(1) & " from " & WScript.Arguments.Item(0) |
||||
wGet = WScript.Arguments.Item(1) |
||||
End If |
||||
Set objCol = GetObject("winmgmts:\\.\root\CIMV2").ExecQuery(wExc,,48) |
||||
For Each objItm in objCol |
||||
For each Prop in objItm.Properties_ |
||||
If LCase(Prop.Name) = LCase(wGet) Then |
||||
WScript.Echo Prop.Name & "=" & Prop.Value |
||||
Exit For |
||||
End If |
||||
Next |
||||
Next |
||||
</script> |
||||
</job> |
||||
<job id="WmiMethod"> |
||||
<script language="VBScript"> |
||||
On Error Resume Next |
||||
wPath = WScript.Arguments.Item(0) |
||||
wMethod = WScript.Arguments.Item(1) |
||||
Set objCol = GetObject("winmgmts:\\.\root\CIMV2:" & wPath) |
||||
objCol.ExecMethod_(wMethod) |
||||
WScript.Quit Err.Number |
||||
</script> |
||||
</job> |
||||
</package> |
@ -1,697 +0,0 @@
@@ -1,697 +0,0 @@
|
||||
'******************************************************************************* |
||||
' Name: OLicenseCleanup.vbs - v 1.24 |
||||
' Author: Microsoft Customer Support Services |
||||
' Copyright (c) Microsoft Corporation |
||||
' |
||||
' Removes all licenses for Office 2013 and 2016 |
||||
' from the (Office) Software Protection Platform |
||||
'******************************************************************************* |
||||
'Option Explicit |
||||
|
||||
Dim oProductInstances, oWmiLocal, oReg, oWShell, oFso |
||||
Dim sQuery, sTemp, sLogDir, sOSinfo, sProfilesDirectory, sCurDir |
||||
Dim f64, fO64, fCScript, fQuiet, fClearO15, fClearO16, fSafeForRoamingUsers |
||||
Dim fClearUserIdentityCache, fSignOutOfWAM |
||||
Dim LogStream |
||||
|
||||
Const SKUFILTER = "O365" 'Removes all licenses that contain O365 in their name |
||||
'Note: SKUFILTER = "" 'Removes all licenses |
||||
' SKUFILTER = "NOTO365" 'Removes all licenses that do not contain O365 in their name |
||||
|
||||
Const PS_WAMSIGNOUT = "SignOutOfWAMAccounts.ps1" |
||||
|
||||
fQuiet = True |
||||
fClearO15 = True |
||||
fClearO16 = True |
||||
fClearUserIdentityCache = False |
||||
fSignOutOfWAM = True |
||||
sLogDir = "" 'Custom log folder/directory. No trailing "\" in the path! |
||||
|
||||
'Set this to False if the script needs to run more than once and you don't |
||||
'have roaming profile users |
||||
fSafeForRoamingUsers = True |
||||
|
||||
|
||||
'******************************************************************************* |
||||
|
||||
|
||||
Const OfficeAppId = "0ff1ce15-a989-479d-af46-f275c6370663" 'Office 2013/2016 |
||||
Const HKLM = &H80000002 |
||||
Const SCRIPTVERSION = "1.24" |
||||
|
||||
|
||||
' MAIN |
||||
On Error Resume Next |
||||
Set oWShell = CreateObject("WScript.Shell") |
||||
|
||||
Initialize |
||||
LogH2 "Cleanup start" |
||||
CleanOSPP SKUFILTER |
||||
ResetUserKey "Common\Identity", "" '"ResetIdentity" |
||||
ResetUserKey "Common\Internet\WebServiceCache", "" '"ResetWebServiceCache |
||||
ResetUserKey "Common\ServicesManagerCache", "" '"ResetServicesManagerCache" |
||||
ResetUserKey "Common\Licensing", "" '"ResetUserLicense" |
||||
ResetUserKey "Registration", "" '"ResetUserRegistration" |
||||
ClearCredmanCache |
||||
ClearSCALicCache |
||||
ClearConfigUser |
||||
ClearVNextLicCache |
||||
If fClearUserIdentityCache Then ClearIdentityCache |
||||
If fSignOutOfWAM Then InvokeSignOutOfWAM |
||||
|
||||
LogH2 "Cleanup end" |
||||
' END |
||||
|
||||
'------------------------------------------------------------------------------- |
||||
' Initialize |
||||
' |
||||
' Initialize script settings |
||||
'------------------------------------------------------------------------------- |
||||
Sub Initialize |
||||
Dim ComputerItem, Item |
||||
Dim sOsVersion |
||||
|
||||
'Check if we're running as 32 bit process on a 64 bit OS |
||||
If InStr(LCase(wscript.path), "syswow64") > 0 Then RelaunchAs64Host |
||||
|
||||
Set oWmiLocal = GetObject("winmgmts:\\.\root\cimv2") |
||||
Set oReg = GetObject("winmgmts:\\.\root\default:StdRegProv") |
||||
Set oFso = CreateObject("Scripting.FileSystemObject") |
||||
|
||||
sTemp = oWShell.ExpandEnvironmentStrings("%TEMP%") |
||||
fCScript = (UCase(Mid(Wscript.FullName, Len(Wscript.Path) + 2, 1)) = "C") |
||||
|
||||
' get Win32_OperatingSystem details |
||||
'---------------------------------- |
||||
Set ComputerItem = oWmiLocal.ExecQuery("Select * from Win32_OperatingSystem") |
||||
For Each Item in ComputerItem |
||||
sOSinfo = sOSinfo & Item.Caption |
||||
sOSinfo = sOSinfo & Item.OtherTypeDescription |
||||
sOSinfo = sOSinfo & ", " & "SP " & Item.ServicePackMajorVersion |
||||
sOSinfo = sOSinfo & ", " & "Version: " & Item.Version |
||||
sOsVersion = Item.Version |
||||
sOSinfo = sOSinfo & ", " & "Codepage: " & Item.CodeSet |
||||
sOSinfo = sOSinfo & ", " & "Country Code: " & Item.CountryCode |
||||
sOSinfo = sOSinfo & ", " & "Language: " & Item.OSLanguage |
||||
Next |
||||
|
||||
DetectOSBitness |
||||
DetectOfficeBitness |
||||
CreateLog |
||||
|
||||
LogOnly "Remove O15 Lic: " & fClearO15 |
||||
LogOnly "Remove O16 Lic: " & fClearO16 |
||||
LogOnly "Quiet mode: " & fQuiet |
||||
|
||||
RegReadExpStringValue HKLM, "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList", "ProfilesDirectory", sProfilesDirectory |
||||
If NOT oFso.FolderExists(sProfilesDirectory) Then |
||||
sProfilesDirectory = oFso.GetParentFolderName(oWShell.ExpandEnvironmentStrings("%userprofile%")) |
||||
End If |
||||
LogOnly "Users profile location: " & sProfilesDirectory |
||||
|
||||
sCurDir = Left(WScript.ScriptFullName, InStrRev( WScript.ScriptFullName, "\")) |
||||
LogOnly "Current Directory: " & sCurDir |
||||
|
||||
End Sub |
||||
|
||||
|
||||
'------------------------------------------------------------------------------- |
||||
' ClearConfigUser |
||||
' |
||||
' clear HKLM cached user license id |
||||
'------------------------------------------------------------------------------- |
||||
Sub ClearConfigUser |
||||
Dim value |
||||
Dim sConfigKey, sRetVal, sCmd |
||||
Dim arrNames, arrTypes |
||||
|
||||
If NOT fClearO16 Then Exit Sub |
||||
|
||||
sConfigKey = "SOFTWARE\Microsoft\Office\ClickToRun\Configuration" |
||||
|
||||
If RegEnumValues(HKLM, sConfigKey, arrNames, arrTypes) Then |
||||
For Each value in arrNames |
||||
If (InStr(LCase(value), LCase(".EmailAddress")) > 0) Or (InStr(LCase(value), LCase(".TenantId")) > 0) Or (LCase(value) = "productkeys") Then |
||||
sCmd = "REG DELETE HKLM\" & sConfigKey & " /v " & value & " /f" |
||||
sRetVal = oWShell.Run(sCmd, 0, True) |
||||
Log "Remove entry: HKLM\" & sConfigKey & "\" & value |
||||
End If |
||||
Next |
||||
End If |
||||
End Sub 'ClearConfigUser |
||||
|
||||
'------------------------------------------------------------------------------- |
||||
' ClearSCALicCache |
||||
' |
||||
' clear local license cache for SharedComputerActivation |
||||
'------------------------------------------------------------------------------- |
||||
Sub ClearSCALicCache |
||||
Dim sLocalAppData, sValue |
||||
|
||||
sLocalAppData = oWShell.ExpandEnvironmentStrings("%localappdata%") |
||||
If fClearO15 Then ClearFolder sLocalAppData & "\Microsoft\Office\15.0\Licensing" |
||||
If fClearO16 Then ClearFolder sLocalAppData & "\Microsoft\Office\16.0\Licensing" |
||||
|
||||
'Check for custom token location |
||||
If RegReadStringValue(HKLM, "Software\Microsoft\Office\16.0\Common\Licensing", "SCLCacheOverrideDirectory", sValue) Then |
||||
ClearSCAFolder sValue |
||||
End If |
||||
|
||||
End Sub 'ClearSCALicCache |
||||
|
||||
'------------------------------------------------------------------------------- |
||||
' ClearVNextLicCache |
||||
' |
||||
' clear local license cache for vNext |
||||
'------------------------------------------------------------------------------- |
||||
Sub ClearVNextLicCache |
||||
Dim sLocalAppData, sValue |
||||
|
||||
sLocalAppData = oWShell.ExpandEnvironmentStrings("%localappdata%") |
||||
ClearFolder sLocalAppData & "\Microsoft\Office\Licenses" |
||||
|
||||
End Sub 'ClearSCALicCache |
||||
|
||||
'------------------------------------------------------------------------------- |
||||
' ClearIdentityCache |
||||
' |
||||
' clear users Windows Identity cache |
||||
'------------------------------------------------------------------------------- |
||||
Sub ClearIdentityCache |
||||
Dim sLocalAppData, sValue |
||||
|
||||
sLocalAppData = oWShell.ExpandEnvironmentStrings("%localappdata%") |
||||
ClearFolder sLocalAppData & "\Microsoft\IdentityCache\1\UD" |
||||
|
||||
End Sub 'ClearIdentityCache |
||||
|
||||
'------------------------------------------------------------------------------- |
||||
' InvokeSignOutOfWAM |
||||
' |
||||
' invokes the external script SignOutOfWAMAccounts.ps1 if the script is found |
||||
' in the same directory |
||||
'------------------------------------------------------------------------------- |
||||
Sub InvokeSignOutOfWAM |
||||
Dim sCmd, sRetVal |
||||
|
||||
If oFso.FileExists(sScriptDir & PS_WAMSIGNOUT) Then |
||||
sCmd = "powershell.exe -executionpolicy unrestricted -noprofile -windowstyle hidden -file " & chr(34) & sCurDir & PS_WAMSIGNOUT & chr(34) & " " & sUITask & " ; exit $LASTEXITCODE" |
||||
Log " Running: " & sCmd |
||||
On Error Resume Next |
||||
If fQuiet Then |
||||
sRetVal = oWShell.Run(sCmd, 0, True) |
||||
Else |
||||
sRetVal = oWShell.Run(sCmd, 2, True) |
||||
End if |
||||
Log " Return value: " & sRetVal |
||||
On Error Goto 0 |
||||
End If |
||||
|
||||
End Sub 'InvokeSignOutOfWAM |
||||
|
||||
'------------------------------------------------------------------------------- |
||||
' ClearUsersRecursive |
||||
' |
||||
' Recursively clear from all local user profiles |
||||
'------------------------------------------------------------------------------- |
||||
Sub ClearUsersRecursive (sFolder) |
||||
Dim sValue |
||||
Dim oFolder, fld |
||||
|
||||
Set oFolder = oFso.GetFolder(sFolder) |
||||
' exclude system protected link folders |
||||
If CBool(oFolder.Attributes AND 1024) Then Exit Sub |
||||
|
||||
On Error Resume Next |
||||
For Each fld In oFolder.SubFolders |
||||
If Err <> 0 Then |
||||
Err.Clear |
||||
Else |
||||
ClearUsersRecursive fld.Path |
||||
End If |
||||
Next |
||||
|
||||
End Sub 'ClearUsersRecursive |
||||
|
||||
'------------------------------------------------------------------------------- |
||||
' ClearFolder |
||||
' |
||||
' clears/deletes the passed in folder |
||||
'------------------------------------------------------------------------------- |
||||
Sub ClearFolder(sDelFld) |
||||
Dim fld, attr |
||||
Dim sCmd |
||||
|
||||
If oFso.FolderExists(sDelFld) Then |
||||
Set fld = oFso.GetFolder(sDelFld) |
||||
'ensure to remove read only flag |
||||
attr = fld.Attributes |
||||
If CBool(attr And 1) Then fld.Attributes = attr And (attr - 1) |
||||
'delete folder |
||||
fld.Delete True |
||||
Set fld = Nothing |
||||
|
||||
'check if removal succeeded. If not try to RD |
||||
If oFso.FolderExists(sDelFld) Then |
||||
sCmd = "cmd.exe /c rd /s " & chr(34) & sDelFld & chr(34) & " /q" |
||||
Log "Remove folder: " & sDelFld |
||||
oWShell.Run sCmd, 0, True |
||||
End If |
||||
End If |
||||
End Sub |
||||
|
||||
'------------------------------------------------------------------------------- |
||||
' ClearCredmanCache |
||||
' |
||||
' clear Office credentials from Windows Credentials Manager Cache |
||||
'------------------------------------------------------------------------------- |
||||
Sub ClearCredmanCache |
||||
Dim oExec, line, key |
||||
Dim sCmd, sRetVal, sCmdOut, sLine |
||||
Dim arrLines, dicRemoveCreds |
||||
|
||||
Set dicRemoveCreds = CreateObject("Scripting.Dictionary") |
||||
|
||||
dicRemoveCreds.Add "MicrosoftOffice1", "MicrosoftOffice1*" |
||||
dicRemoveCreds.Add "msteams", "msteams*" |
||||
dicRemoveCreds.Add "Microsoft_OC", "Microsoft_OC*" |
||||
dicRemoveCreds.Add "OneDrive Cached", "OneDrive*" |
||||
|
||||
For Each key In dicRemoveCreds.Keys |
||||
sCmd = "cmdkey.exe /list:" & dicRemoveCreds.Item(key) |
||||
Set oExec = oWShell.Exec(sCmd) |
||||
sCmdOut = oExec.StdOut.ReadAll() |
||||
Do While oExec.Status = 0 |
||||
WScript.Sleep 100 |
||||
Loop |
||||
arrLines = Split(sCmdOut) |
||||
For Each line In arrLines |
||||
If (InStr(line, key) > 0 Or InStr(line, "OneDrive"))And Not InStr(line, dicRemoveCreds.Item(key)) > 0 Then |
||||
fBuildString = True |
||||
End If |
||||
If fBuildString And Len(line) < 1 Then |
||||
fBuildString = False |
||||
RunCmdkey sLine |
||||
End If |
||||
If fBuildString Then |
||||
sLine = sLine & " " & line |
||||
End If |
||||
Next |
||||
Next 'key |
||||
End Sub 'ClearCredmanCache |
||||
|
||||
|
||||
'------------------------------------------------------------------------------- |
||||
' RunCmdkey |
||||
' |
||||
' call CmdKey.exe to remove the credentials from CredMan |
||||
'------------------------------------------------------------------------------- |
||||
Sub RunCmdkey (sLine) |
||||
Dim sCmd, sRetVal |
||||
|
||||
sLine = Replace(sLine, vbCrLf, "") |
||||
sLine = Replace(sLine, vbLf, "") |
||||
sLine = Trim(sLine) |
||||
sCmd = "cmdkey.exe /delete:" & Chr(34) & sLine & Chr(34) |
||||
Log "Remove from CredmanCache: " & sLine |
||||
Log "Execute removal command: " & sCmd |
||||
sRetVal = oWShell.Run(sCmd, 0, True) |
||||
Log sRetVal |
||||
sLine = "" |
||||
End Sub |
||||
|
||||
'------------------------------------------------------------------------------- |
||||
' ResetUserKey |
||||
' |
||||
' attempts to delete the passed in key by direct delete and |
||||
' adds it to UserSetting scope to be reset on next application launch |
||||
'------------------------------------------------------------------------------- |
||||
Sub ResetUserKey(sRegKey, sCustomName) |
||||
Dim sSettingsKey, sCount, sRetVal, sCmd, sCUserKey, sSquirrelKey, sKey |
||||
Dim key |
||||
Dim iCount |
||||
Dim arrKey |
||||
|
||||
If fClearO15 Then ResetUserKeyEx sRegKey, sCustomName, "15" |
||||
If fClearO16 Then ResetUserKeyEx sRegKey, sCustomName, "16" |
||||
|
||||
End Sub 'ResetUserKey |
||||
|
||||
'------------------------------------------------------------------------------- |
||||
' ResetUserKeyEx |
||||
' |
||||
' executes the version specific tasks for ResetUserKey |
||||
'------------------------------------------------------------------------------- |
||||
Sub ResetUserKeyEx(sRegKey, sCustomName, iVM) |
||||
Dim sSettingsKey, sCount, sRetVal, sCmd, sCUserKey, sSquirrelKey, sKey |
||||
Dim key |
||||
Dim iCount |
||||
Dim arrKey |
||||
|
||||
If sCustomName = "" Then sCustomName = "CustomUserReset" |
||||
|
||||
' attempt direct delete |
||||
sCUserKey = "HKCU\Software\Microsoft\Office\" & iVM & ".0\" & sRegKey |
||||
Log "Remove key " & sCUserKey |
||||
sCmd = "REG DELETE " & sCUserKey & " /f" |
||||
sRetVal = oWShell.Run(sCmd, 0, True) |
||||
|
||||
'create user settings key to cover reset for other profiles |
||||
sSettingsKey = "SOFTWARE\Wow6432Node\Microsoft\Office\" & iVM & ".0\User Settings" |
||||
If (f64 And fO64) Or (Not f64) Then sSettingsKey = "SOFTWARE\Microsoft\Office\" & iVM & ".0\User Settings" |
||||
|
||||
sSquirrelKey = sCustomName & "\Delete\Software\Microsoft\Office\" & iVM & ".0\" & sRegKey |
||||
arrKey = Split(sSquirrelKey, "\") |
||||
sKey = sSettingsKey |
||||
For Each key In arrKey |
||||
sKey = sKey & "\" & key |
||||
oReg.CreateKey HKLM, sKey |
||||
Next |
||||
|
||||
iCount = 1 |
||||
If Not fSafeForRoamingUsers Then |
||||
If RegReadDWordValue(HKLM, sSettingsKey & "\" & sCustomName, "Count", sCount) Then iCount = CInt(sCount) + 1 |
||||
End If |
||||
oReg.SetDWordValue HKLM, sSettingsKey & "\" & sCustomName, "Count", iCount |
||||
oReg.SetDWordValue HKLM, sSettingsKey & "\" & sCustomName, "Order", 1 |
||||
LogOnly "Add SettingsKey: HKLM\" & sKey |
||||
LogOnly "Count: " & iCount |
||||
|
||||
End Sub 'ResetUserKeyEx |
||||
|
||||
'------------------------------------------------------------------------------- |
||||
' CleanOSPP |
||||
' |
||||
' unpkeys the licenses from OSPP |
||||
'------------------------------------------------------------------------------- |
||||
Sub CleanOSPP (sFilter) |
||||
Dim pi |
||||
Dim oProductInstances |
||||
|
||||
' Initialize the software protection platform object with a filter on Office 2013/2016 products |
||||
If GetVersionNT > 601 Then |
||||
Set oProductInstances = oWmiLocal.ExecQuery("SELECT ID, ApplicationId, PartialProductKey, Description, Name, ProductKeyID FROM SoftwareLicensingProduct WHERE ApplicationId = '" & OfficeAppId & "' " & "AND PartialProductKey <> NULL") |
||||
Else |
||||
Set oProductInstances = oWmiLocal.ExecQuery("SELECT ID, ApplicationId, PartialProductKey, Description, Name, ProductKeyID FROM OfficeSoftwareProtectionProduct WHERE ApplicationId = '" & OfficeAppId & "' " & "AND PartialProductKey <> NULL") |
||||
End If |
||||
|
||||
' Remove all licenses |
||||
For Each pi in oProductInstances |
||||
Log "License: " & pi.Name |
||||
If NOT IsNull(pi) Then |
||||
If InStr(pi.Name, sFilter) > 0 Or sFilter = "" Then |
||||
Log "Uninstall ProductKey: " & pi.Name & " - Key: " & pi.ProductKeyID |
||||
pi.UninstallProductKey(pi.ProductKeyID) |
||||
End If |
||||
If UCase(sFilter) = "NOTO365" Then |
||||
If Not InStr(pi.Name, "O365") > 0 Then |
||||
Log "Uninstall ProductKey: " & pi.Name & " - Key: " & pi.ProductKeyID |
||||
pi.UninstallProductKey(pi.ProductKeyID) |
||||
End If |
||||
End If |
||||
End If |
||||
Next 'pi |
||||
End Sub 'CleanOSPP |
||||
|
||||
'------------------------------------------------------------------------------- |
||||
' DetectOfficeBitness |
||||
' |
||||
' detect bitness of Office |
||||
'------------------------------------------------------------------------------- |
||||
Sub DetectOfficeBitness () |
||||
Dim sOPlatform, sInstallRootPath |
||||
|
||||
fO64 = False |
||||
If Not f64 Then Exit Sub |
||||
If RegReadStringValue(HKLM, "SOFTWARE\Microsoft\Office\ClickToRun\Configuration", "platform", sOPlatform) Then |
||||
fO64 = (sOPlatform = "x64") |
||||
Exit Sub |
||||
End If |
||||
If RegReadStringValue(HKLM, "SOFTWARE\Microsoft\Office\15.0\ClickToRun\Configuration", "platform", sOPlatform) Then |
||||
fO64 = (sOPlatform = "x64") |
||||
Exit Sub |
||||
End If |
||||
If RegReadStringValue(HKLM, "SOFTWARE\Microsoft\Office\ClickToRun\propertyBag", "Platform", sOPlatform) Then |
||||
fO64 = (sOPlatform = "x64") |
||||
Exit Sub |
||||
End If |
||||
If RegReadStringValue(HKLM, "SOFTWARE\Microsoft\Office\15.0\ClickToRun\propertyBag", "Platform", sOPlatform) Then |
||||
fO64 = (sOPlatform = "x64") |
||||
Exit Sub |
||||
End If |
||||
If RegReadStringValue(HKLM, "SOFTWARE\Wow6432Node\Microsoft\Office\Common\InstallRoot", "Path", sInstallRootPath) Then |
||||
'fO64 = Not (InStr(sInstallRootPath, "(x86)") > 0) |
||||
fO64 = False |
||||
Exit Sub |
||||
End If |
||||
If RegReadStringValue(HKLM, "SOFTWARE\Wow6432Node\Microsoft\Office\15.0\Common\InstallRoot", "Path", sInstallRootPath) Then |
||||
'fO64 = Not (InStr(sInstallRootPath, "(x86)") > 0) |
||||
fO64 = False |
||||
Exit Sub |
||||
End If |
||||
If RegReadStringValue(HKLM, "SOFTWARE\Microsoft\Office\Common\InstallRoot", "Path", sInstallRootPath) Then |
||||
'fO64 = Not (InStr(sInstallRootPath, "(x86)") > 0) |
||||
fO64 = True |
||||
Exit Sub |
||||
End If |
||||
If RegReadStringValue(HKLM, "SOFTWARE\Microsoft\Office\15.0\Common\InstallRoot", "Path", sInstallRootPath) Then |
||||
'fO64 = Not (InStr(sInstallRootPath, "(x86)") > 0) |
||||
fO64 = True |
||||
Exit Sub |
||||
End If |
||||
|
||||
End Sub 'DetectOfficeBitness |
||||
|
||||
'------------------------------------------------------------------------------- |
||||
' DetectOSBitness |
||||
' |
||||
' detect bitness of the operating system |
||||
'------------------------------------------------------------------------------- |
||||
Sub DetectOSBitness () |
||||
Dim ComputerItem, item |
||||
|
||||
Set ComputerItem = oWmiLocal.ExecQuery("Select * from Win32_ComputerSystem") |
||||
For Each item In ComputerItem |
||||
f64 = Instr(Left(item.SystemType, 3), "64") > 0 |
||||
Next |
||||
End Sub 'DetectOSBitness |
||||
|
||||
'------------------------------------------------------------------------------- |
||||
' GetVersionNT |
||||
' |
||||
' Calculate the VerionNT number as integer |
||||
'------------------------------------------------------------------------------- |
||||
Function GetVersionNT () |
||||
Dim sOsVersion |
||||
Dim arrVersion |
||||
Dim qOS |
||||
Dim oOsItem |
||||
|
||||
Set qOS = oWmiLocal.ExecQuery( "Select * from Win32_OperatingSystem") |
||||
For Each oOsItem in qOS |
||||
sOsVersion = oOsItem.Version |
||||
Next |
||||
arrVersion = Split( sOsVersion, GetDelimiter( sOsVersion)) |
||||
GetVersionNT = CInt( arrVersion( 0)) * 100 + CInt( arrVersion( 1)) |
||||
End Function |
||||
|
||||
'------------------------------------------------------------------------------- |
||||
' GetDelimiter |
||||
' |
||||
' Returns the delimiter in a version string |
||||
'------------------------------------------------------------------------------- |
||||
Function GetDelimiter (sVersion) |
||||
Dim iCnt, iAsc |
||||
|
||||
GetDelimiter = " " |
||||
For iCnt = 1 To Len(sVersion) |
||||
iAsc = Asc(Mid(sVersion, iCnt, 1)) |
||||
If Not (iASC >= 48 And iASC <= 57) Then |
||||
GetDelimiter = Mid(sVersion, iCnt, 1) |
||||
Exit Function |
||||
End If |
||||
Next 'iCnt |
||||
End Function |
||||
|
||||
'------------------------------------------------------------------------------- |
||||
' RegReadDWordValue |
||||
' |
||||
' Check if a string value exists and return on zero if not |
||||
'------------------------------------------------------------------------------- |
||||
Function RegReadDWordValue(hDefKey, sSubKeyName, sName, sValue) |
||||
Dim RetVal |
||||
|
||||
RetVal = oReg.GetDWORDValue(hDefKey, sSubKeyName, sName, sValue) |
||||
RegReadDWordValue = (RetVal = 0) |
||||
|
||||
End Function 'RegReadDWordValue |
||||
|
||||
'------------------------------------------------------------------------------- |
||||
' RegReadStringValue |
||||
' |
||||
' Check if a string value exists and return on zero if not |
||||
'------------------------------------------------------------------------------- |
||||
Function RegReadStringValue(hDefKey, sSubKeyName, sName, sValue) |
||||
Dim RetVal |
||||
|
||||
RetVal = oReg.GetStringValue(hDefKey, sSubKeyName, sName, sValue) |
||||
RegReadStringValue = (RetVal = 0) |
||||
|
||||
End Function 'RegReadSringValue |
||||
|
||||
'------------------------------------------------------------------------------- |
||||
' RegReadExpStringValue |
||||
' |
||||
' Check if an expanded string value exists and return on zero if not |
||||
'------------------------------------------------------------------------------- |
||||
Function RegReadExpStringValue(hDefKey, sSubKeyName, sName, sValue) |
||||
Dim RetVal |
||||
|
||||
RetVal = oReg.GetExpandedStringValue(hDefKey, sSubKeyName, sName, sValue) |
||||
RegReadStringValue = (RetVal = 0) |
||||
|
||||
End Function 'RegReadSringValue |
||||
|
||||
'------------------------------------------------------------------------------- |
||||
' RegEnumValues |
||||
' |
||||
' Enumerate a registry key to return all values |
||||
'------------------------------------------------------------------------------- |
||||
Function RegEnumValues(hDefKey, sSubKeyName, arrNames, arrTypes) |
||||
Dim RetVal |
||||
|
||||
RetVal = oReg.EnumValues(hDefKey, sSubKeyName, arrNames, arrTypes) |
||||
RegEnumValues = (RetVal = 0) AND IsArray(arrNames) AND IsArray(arrTypes) |
||||
End Function 'RegEnumValues |
||||
|
||||
'------------------------------------------------------------------------------- |
||||
' RelaunchAs64Host |
||||
' |
||||
' Relaunch self with 64 bit CScript host |
||||
'------------------------------------------------------------------------------- |
||||
Sub RelaunchAs64Host |
||||
Dim Argument, sCmd |
||||
Dim fQuietRelaunch |
||||
|
||||
fQuietRelaunch = False |
||||
sCmd = Replace(LCase(wscript.Path), "syswow64", "sysnative") & "\cscript.exe " & Chr(34) & WScript.scriptFullName & Chr(34) |
||||
If fQuiet Then fQuietRelaunch = True |
||||
If Wscript.Arguments.Count > 0 Then |
||||
For Each Argument in Wscript.Arguments |
||||
sCmd = sCmd & " " & chr(34) & Argument & chr(34) |
||||
Select Case UCase(Argument) |
||||
Case "/Q", "/QUIET" |
||||
fQuietRelaunch = True |
||||
End Select |
||||
Next 'Argument |
||||
End If |
||||
sCmd = sCmd & " /ChangedHostBitness" |
||||
If fQuietRelaunch Then |
||||
sCmd = Replace (sCmd, "\cscript.exe", "\wscript.exe") |
||||
Wscript.Quit CLng(oWShell.Run (sCmd, 0, True)) |
||||
Else |
||||
Wscript.Quit CLng(oWShell.Run (sCmd, 1, True)) |
||||
End If |
||||
|
||||
End Sub 'RelaunchAs64Host |
||||
|
||||
'------------------------------------------------------------------------------- |
||||
' CreateLog |
||||
' |
||||
' Create the removal log file |
||||
'------------------------------------------------------------------------------- |
||||
Sub CreateLog |
||||
Dim DateTime |
||||
Dim sLogName |
||||
|
||||
On Error Resume Next |
||||
' create the log file |
||||
Set DateTime = CreateObject("WbemScripting.SWbemDateTime") |
||||
DateTime.SetVarDate Now, True |
||||
If sLogDir = "" Then sLogDir = sTemp |
||||
sLogName = sLogDir & "\" & oWShell.ExpandEnvironmentStrings("%COMPUTERNAME%") |
||||
sLogName = sLogName & "_" & Left(DateTime.Value, 14) |
||||
sLogName = sLogName & "_OLicenseClean.txt" |
||||
Err.Clear |
||||
Set LogStream = oFso.CreateTextFile(sLogName, True, True) |
||||
If Err <> 0 Then |
||||
Err.Clear |
||||
sLogDir = sTemp |
||||
sLogName = sLogDir & "\" & oWShell.ExpandEnvironmentStrings("%COMPUTERNAME%") |
||||
sLogName = sLogName & "_" & Left(DateTime.Value, 14) |
||||
sLogName = sLogName & "_oLicenseClean.txt" |
||||
Set LogStream = oFso.CreateTextFile(sLogName, True, True) |
||||
End If |
||||
On Error Goto 0 |
||||
|
||||
LogH2 "Microsoft Customer Support Services - Office License Reset Utility" & vbCrLf & vbCrLf & _ |
||||
"Version: " & vbTab & SCRIPTVERSION & vbCrLf & _ |
||||
"64 bit OS: " & vbTab & f64 & vbCrLf & _ |
||||
"64 bit Office: " & vbTab & fO64 & vbCrLf & _ |
||||
"Cleanup start: " & vbTab & Time |
||||
LogH2 "OS Details: " & sOSinfo & vbCrLf |
||||
End Sub 'CreateLog |
||||
|
||||
'------------------------------------------------------------------------------- |
||||
' LogH |
||||
' |
||||
' Write a header log string to the log file |
||||
'------------------------------------------------------------------------------- |
||||
Sub LogH (sLog) |
||||
LogStream.WriteLine "" |
||||
sLog = sLog & vbCrLf & String(Len(sLog), "=") |
||||
If NOT fQuiet AND fCScript Then wscript.echo "" |
||||
If NOT fQuiet AND fCScript Then wscript.echo sLog |
||||
LogStream.WriteLine sLog |
||||
End Sub 'Logh |
||||
|
||||
'------------------------------------------------------------------------------- |
||||
' LogH1 |
||||
' |
||||
' Write a header log string to the log file |
||||
'------------------------------------------------------------------------------- |
||||
Sub LogH1 (sLog) |
||||
LogStream.WriteLine "" |
||||
sLog = sLog & vbCrLf & String(Len(sLog), "-") |
||||
If NOT fQuiet AND fCScript Then wscript.echo "" |
||||
If NOT fQuiet AND fCScript Then wscript.echo sLog |
||||
LogStream.WriteLine sLog |
||||
End Sub 'LogH1 |
||||
|
||||
'------------------------------------------------------------------------------- |
||||
' LogH2 |
||||
' |
||||
' Write w/o indent Cmd window and the log file |
||||
'------------------------------------------------------------------------------- |
||||
Sub LogH2 (sLog) |
||||
If NOT fQuiet AND fCScript Then wscript.echo sLog |
||||
LogStream.WriteLine "" |
||||
LogStream.WriteLine sLog |
||||
End Sub 'LogH2 |
||||
|
||||
'------------------------------------------------------------------------------- |
||||
' Log |
||||
' |
||||
' Echos the log string to the Cmd window and the log file |
||||
'------------------------------------------------------------------------------- |
||||
Sub Log (sLog) |
||||
If NOT fQuiet AND fCScript Then wscript.echo sLog |
||||
If sLog = "" Then |
||||
LogStream.WriteLine |
||||
Else |
||||
LogStream.WriteLine " " & Time & ": " & sLog |
||||
End If |
||||
End Sub 'Log |
||||
|
||||
'------------------------------------------------------------------------------- |
||||
' LogOnly |
||||
' |
||||
' Commits the log string to the log file |
||||
'------------------------------------------------------------------------------- |
||||
Sub LogOnly (sLog) |
||||
If sLog = "" Then |
||||
LogStream.WriteLine |
||||
Else |
||||
LogStream.WriteLine " " & Time & ": " & sLog |
||||
End If |
||||
End Sub 'Log |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,27 +0,0 @@
@@ -1,27 +0,0 @@
|
||||
if(-not [Windows.Foundation.Metadata.ApiInformation,Windows,ContentType=WindowsRuntime]::IsMethodPresent("Windows.Security.Authentication.Web.Core.WebAuthenticationCoreManager", "FindAllAccountsAsync")) |
||||
{ |
||||
throw "This script is not supported on this Windows version. Please, use CleanupWPJ.cmd." |
||||
} |
||||
|
||||
Add-Type -AssemblyName System.Runtime.WindowsRuntime |
||||
|
||||
Function AwaitAction($WinRtAction) { |
||||
$asTask = ([System.WindowsRuntimeSystemExtensions].GetMethods() | ? { $_.Name -eq 'AsTask' -and $_.GetParameters().Count -eq 1 -and !$_.IsGenericMethod })[0] |
||||
$netTask = $asTask.Invoke($null, @($WinRtAction)) |
||||
$netTask.Wait(-1) | Out-Null |
||||
} |
||||
|
||||
Function Await($WinRtTask, $ResultType) { |
||||
$asTaskGeneric = ([System.WindowsRuntimeSystemExtensions].GetMethods() | ? { $_.Name -eq 'AsTask' -and $_.GetParameters().Count -eq 1 -and $_.GetParameters()[0].ParameterType.Name -eq 'IAsyncOperation`1' })[0] |
||||
$asTask = $asTaskGeneric.MakeGenericMethod($ResultType) |
||||
$netTask = $asTask.Invoke($null, @($WinRtTask)) |
||||
$netTask.Wait(-1) | Out-Null |
||||
$netTask.Result |
||||
} |
||||
|
||||
$provider = Await ([Windows.Security.Authentication.Web.Core.WebAuthenticationCoreManager,Windows,ContentType=WindowsRuntime]::FindAccountProviderAsync("https://login.microsoft.com", "organizations")) ([Windows.Security.Credentials.WebAccountProvider,Windows,ContentType=WindowsRuntime]) |
||||
|
||||
$accounts = Await ([Windows.Security.Authentication.Web.Core.WebAuthenticationCoreManager,Windows,ContentType=WindowsRuntime]::FindAllAccountsAsync($provider, "d3590ed6-52b3-4102-aeff-aad2292ab01c")) ([Windows.Security.Authentication.Web.Core.FindAllAccountsResult,Windows,ContentType=WindowsRuntime]) |
||||
|
||||
$accounts.Accounts | % { AwaitAction ($_.SignOutAsync(“d3590ed6-52b3-4102-aeff-aad2292ab01c”)) } |
||||
|
Loading…
Reference in new issue