forked from SoftwareRat/slimdown10-gh
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnmountCleanUp.cmd
More file actions
112 lines (92 loc) · 3.24 KB
/
UnmountCleanUp.cmd
File metadata and controls
112 lines (92 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
@echo off
TITLE Unmount and clean up script
CLS
::
:: This script is only needed if execution of Slimdown10 gets interrupted,
:: leaving garbage behind.
::
:: Orherwise, It has no effect because normally Slimdown10 has built in clean up.
::
REM Check admin rights
fsutil dirty query %systemdrive% >nul 2>&1
if ERRORLEVEL 1 (
ECHO.
ECHO.
ECHO =============================================
ECHO The script needs Administrator permissions!
ECHO.
ECHO Please run it as the Administrator.
ECHO =============================================
ECHO.
PAUSE >NUL
goto end
)
REM Check parenthesis in script PATH, which brakes subsequent for loops
set incorrectPath=0
echo "%~dp0" | findstr /l /c:"(" >nul 2>&1 && set incorrectPath=1
echo "%~dp0" | findstr /l /c:")" >nul 2>&1 && set incorrectPath=1
if not "%incorrectPath%"=="0" (
ECHO.
ECHO.
ECHO ================================================================
ECHO Script cannot be run from this location!
ECHO Current location contatins parenthesis in the PATH.
ECHO.
ECHO Please copy and run script from Desktop or another directory!
ECHO ================================================================
ECHO.
PAUSE >NUL
goto end
)
set DISM=
set "HostArchitecture=x86"
if exist "%WinDir%\SysWOW64" set "HostArchitecture=amd64"
if exist "%~dp0hotfixes\InternalDISM.txt" goto useInternalDISM
for /f "delims=" %%i in ('where dism 2^>nul') do (set "DISM=%%i")
if "%DISM%"=="" goto useInternalDISM
if not exist "%DISM%" goto useInternalDISM
%DISM% /English /? | findstr /l /i /c:"Version: 10.0.19041" >nul 2>&1 && goto skipInternalDISM
%DISM% /English /? | findstr /r /i /c:"Version: 10\.0\.1904[2-9]" >nul 2>&1 && goto skipInternalDISM
%DISM% /English /? | findstr /r /i /c:"Version: 10\.0\.190[5-9]" >nul 2>&1 && goto skipInternalDISM
%DISM% /English /? | findstr /r /i /c:"Version: 10\.0\.19[1-9]" >nul 2>&1 && goto skipInternalDISM
%DISM% /English /? | findstr /r /i /c:"Version: 10\.0\.[2-9]" >nul 2>&1 && goto skipInternalDISM
%DISM% /English /? | findstr /r /i /c:"Version: 10\.[1-9]" >nul 2>&1 && goto skipInternalDISM
%DISM% /English /? | findstr /r /i /c:"Version: 1[1-9]\." >nul 2>&1 && goto skipInternalDISM
:useInternalDISM
set "DISM=%~dp0tools\%HostArchitecture%\DISM\dism.exe"
:skipInternalDISM
ECHO.
ECHO.
ECHO ================================================================
ECHO Unmounting mounted registry keys...
ECHO ================================================================
ECHO.
reg unload HKLM\TK_DEFAULT >nul 2>&1
reg unload HKLM\TK_NTUSER >nul 2>&1
reg unload HKLM\TK_SOFTWARE >nul 2>&1
reg unload HKLM\TK_SYSTEM >nul 2>&1
ECHO.
ECHO Done!
ECHO.
ECHO.
ECHO.
ECHO ================================================================
ECHO Unmounting mounted images...
ECHO ================================================================
ECHO.
if exist "%~dp0mount\Windows\explorer.exe" (
%DISM% /English /Unmount-Wim /MountDir:"%~dp0mount" /Discard
)
rd /s /q "%~dp0mount" >nul 2>&1
mkdir "%~dp0mount" >nul 2>&1
%DISM% /English /Cleanup-Mountpoints
del /q /f "%~dp0hotfixes\InternalDISM.txt" >nul 2>&1
ECHO.
ECHO.
ECHO All done!
ECHO.
ECHO.
ECHO Press any key to end the script.
ECHO.
PAUSE >NUL
:end