-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstall-WinHlp32.cmd
More file actions
230 lines (192 loc) · 8.78 KB
/
Install-WinHlp32.cmd
File metadata and controls
230 lines (192 loc) · 8.78 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
@echo off
setlocal EnableExtensions
setlocal EnableDelayedExpansion
set ScriptDir=%~dp0
set ScriptDir=%ScriptDir:~0,-1%
echo +----------------------------------------------------------------------------+
echo ^| Windows Help program ^(WinHlp32^) installer ^|
echo ^| ^|
echo ^| Revision 1 ^|
echo ^| July 21st, 2020 ^|
echo ^| Copyright ^(c^) 2020 Wrong-Code. All rights reserved. ^|
echo ^| ^|
echo ^| Based on the original script by Komeil Bahmanpour. ^|
echo +----------------------------------------------------------------------------+
echo.
:: ---------------------------------------------------------------------------
:: Check if running as an administrator
"%SystemRoot%\System32\net.exe" session >nul 2>&1
if %ERRORLEVEL% NEQ 0 (
echo This script must be run with administrative privileges.
goto :ERROR
)
:: ---------------------------------------------------------------------------
:: Check if wget is available
if not exist "%ScriptDir%\wget.exe" (
echo wget.exe is not available. Please download it from
echo.
echo https://eternallybored.org/misc/wget/releases/wget-1.20.3-win32.zip
echo.
echo ^(or use a newer/different build^) and place it in this script's directory.
goto :ERROR
)
:: ---------------------------------------------------------------------------
:: Windows version detection
echo Setup is detecting the Windows version...
ver | "%SystemRoot%\System32\findstr.exe" /il "10\.0\." >nul
if %ERRORLEVEL% EQU 0 (
echo Microsoft Windows 10 / Windows Server 2016/2019 detected.
set WindowsVersion=10_2016_2019
rem No direct support for Windows 10 / 2016 / 2019. We will use the KB for
rem Windows 8.1 / 2012 R2 to hack in the needed files.
if %PROCESSOR_ARCHITECTURE% EQU AMD64 (
set URL=https://download.microsoft.com/download/A/5/6/A5651A53-2487-43C6-835A-744EB9C72579/Windows8.1-KB917607-x64.msu
) else (
set URL=https://download.microsoft.com/download/3/8/C/38C68F7C-1769-4089-BF21-3F5D8A556CBC/Windows8.1-KB917607-x86.msu
)
goto :DownloadKB
)
ver | "%SystemRoot%\System32\findstr.exe" /il "6\.3\." >nul
if %ERRORLEVEL% EQU 0 (
echo Microsoft Windows 8.1 / Windows Server 2012 R2 detected.
set WindowsVersion=8.1_2012R2
if %PROCESSOR_ARCHITECTURE% EQU AMD64 (
set URL=https://download.microsoft.com/download/A/5/6/A5651A53-2487-43C6-835A-744EB9C72579/Windows8.1-KB917607-x64.msu
) else (
set URL=https://download.microsoft.com/download/3/8/C/38C68F7C-1769-4089-BF21-3F5D8A556CBC/Windows8.1-KB917607-x86.msu
)
goto :DownloadKB
)
ver | "%SystemRoot%\System32\findstr.exe" /il "6\.2\." >nul
if %ERRORLEVEL% EQU 0 (
echo Microsoft Windows 8 / Windows Server 2012 detected.
set WindowsVersion=8_2012
if %PROCESSOR_ARCHITECTURE% EQU AMD64 (
set URL=https://download.microsoft.com/download/2/0/0/200C7BAF-48D7-4C0A-9C12-088CBA3DB13B/Windows8-RT-KB917607-x64.msu
) else (
set URL=https://download.microsoft.com/download/2/0/0/200C7BAF-48D7-4C0A-9C12-088CBA3DB13B/Windows8-RT-KB917607-x86.msu
)
goto :DownloadKB
)
ver | "%SystemRoot%\System32\findstr.exe" /il "6\.1\." >nul
if %ERRORLEVEL% EQU 0 (
echo Microsoft Windows 7 / Windows Server 2008 R2 detected.
set WindowsVersion=7_2008R2
if %PROCESSOR_ARCHITECTURE% EQU AMD64 (
set URL=https://download.microsoft.com/download/9/A/8/9A8FCFAA-78A0-49F5-8C8E-4EAE185F515C/Windows6.1-KB917607-x64.msu
) else (
set URL=https://download.microsoft.com/download/9/A/8/9A8FCFAA-78A0-49F5-8C8E-4EAE185F515C/Windows6.1-KB917607-x86.msu
)
goto :DownloadKB
)
ver | "%SystemRoot%\System32\findstr.exe" /il "6\.0\." >nul
if %ERRORLEVEL% EQU 0 (
echo Microsoft Windows Vista / Windows Server 2008 detected.
set WindowsVersion=Vista_2008
if %PROCESSOR_ARCHITECTURE% EQU AMD64 (
set URL=https://download.microsoft.com/download/4/d/5/4d56f3c4-e65a-402b-826f-b87ef81fc31c/Windows6.0-KB917607-x64.msu
) else (
set URL=https://download.microsoft.com/download/4/d/5/4d56f3c4-e65a-402b-826f-b87ef81fc31c/Windows6.0-KB917607-x86.msu
)
goto :DownloadKB
)
echo Unsupported Windows version. This script must be run under one of
echo the following operating systems:
echo.
echo * Microsoft Windows 10 / Windows Server 2016/2019
echo * Microsoft Windows 8.1 / Windows Server 2012 R2
echo * Microsoft Windows 8 / Windows Server 2012
echo * Microsoft Windows 7 / Windows Server 2008 R2
echo * Microsoft Windows Vista / Windows Server 2008
goto :ERROR
:: ---------------------------------------------------------------------------
:: Download the Windows KB
:DownloadKB
echo Downloading the Windows KB...
"%ScriptDir%\wget.exe" -q -O "%TEMP%\winhlp.wusa" "%URL%"
if not exist "%TEMP%\winhlp.wusa" (
echo Could not download the Windows KB from %URL%
goto :ERROR
)
:: ---------------------------------------------------------------------------
:: Preparing for the installation
echo Terminating all the running instances of WinHlp32...
"%SystemRoot%\System32\taskkill.exe" /f /im WinHlp32.exe /t >nul 2>&1
:: ---------------------------------------------------------------------------
:: Apply the KB (except on Windows 10 / 2016 / 2019)
if %WindowsVersion% NEQ 10_2016_2019 (
echo Applying the Windows KB...
"%SystemRoot%\System32\wusa.exe" "%TEMP%\winhlp.wusa" /quiet /norestart
if %ERRORLEVEL% NEQ 0 (
goto :ERROR
)
goto :EXIT
)
:: ---------------------------------------------------------------------------
:: On Windows 10 / 2016 / 2019, we need to extract the .cab from the .wusa
:: file, and then expand it
echo Expanding the .cab file...
mkdir "%TEMP%\winhlp32_expand" >nul 2>&1
"%SystemRoot%\System32\expand.exe" -F:Windows*.cab "%TEMP%\winhlp.wusa" "%TEMP%\winhlp32_expand" >nul 2>&1
for %%f in ("%TEMP%\winhlp32_expand\*.cab") do (
"%SystemRoot%\System32\expand.exe" -R -F:* "%%f" "%TEMP%\winhlp32_expand" >nul 2>&1
)
:: Get the MUI language
for /f "delims=" %%i in ('wmic os get MUILanguages ^| find "{"') do set MuiLang=%%i
for /f delims^=^"^ tokens^=2 %%i in ('echo %MuiLang%') do set MuiLang=%%i
:: Find the proper EXE/MUI source directories
for /f "delims=" %%f in ('dir /ad /b "%TEMP%\winhlp32_expand\%PROCESSOR_ARCHITECTURE%*" ^| find /v "resources"') do (
set SrcExeDir=%TEMP%\winhlp32_expand\%%f
)
for /f "delims=" %%f in ('dir /ad /b "%TEMP%\winhlp32_expand\%PROCESSOR_ARCHITECTURE%*%MuiLang%*"') do (
set SrcMuiDir=%TEMP%\winhlp32_expand\%%f
)
:: ---------------------------------------------------------------------------
:: Hack in the extracted files
echo Installing the WinHlp32 system files...
for %%f in ("%SrcExeDir%\*.*") do (
echo %%~nxf
set sysfile=%SystemRoot%\%%~nxf
rem Take care of the existing WinHlp32 stubs
if exist "!sysfile!" (
"%SystemRoot%\System32\takeown.exe" /f "!sysfile!" >nul 2>&1
"%SystemRoot%\System32\icacls.exe" "!sysfile!" /grant "%UserName%":F >nul 2>&1
)
rem Replace the system file
"%SystemRoot%\System32\xcopy.exe" "%%f" "%SystemRoot%" /r /y /h /q >nul 2>&1
if %ERRORLEVEL% NEQ 0 goto :COPYERROR
)
for %%f in ("%SrcMuiDir%\*.*") do (
echo %MuiLang%\%%~nxf
set sysfile=%SystemRoot%\%MuiLang%\%%~nxf
rem Take care of the existing WinHlp32 stubs
if exist "!sysfile!" (
"%SystemRoot%\System32\takeown.exe" /f "!sysfile!" >nul 2>&1
"%SystemRoot%\System32\icacls.exe" "!sysfile!" /grant "%UserName%":F >nul 2>&1
)
rem Replace the system file
"%SystemRoot%\System32\xcopy.exe" "%%f" "%SystemRoot%\%MuiLang%" /r /y /h /q >nul 2>&1
if %ERRORLEVEL% NEQ 0 goto :COPYERROR
)
echo Fixing the ACL...
"%SystemRoot%\System32\icacls.exe" "%SystemRoot%" /restore "%ScriptDir%\WinHlp32_Exe_ACL.txt" /c >nul 2>&1
"%SystemRoot%\System32\icacls.exe" "%SystemRoot%\%MuiLang%" /restore "%ScriptDir%\WinHlp32_MUI_ACL.txt" /c >nul 2>&1
echo Updating the registry...
"%SystemRoot%\System32\reg.exe" add "HKLM\SOFTWARE\Microsoft\WinHelp" /v "AllowProgrammaticMacros" /t REG_DWORD /d "0x00000001" /f >nul 2>&1
"%SystemRoot%\System32\reg.exe" add "HKLM\SOFTWARE\Microsoft\WinHelp" /v "AllowIntranetAccess" /t REG_DWORD /d "0x00000001" /f >nul 2>&1
if %PROCESSOR_ARCHITECTURE% EQU AMD64 (
"%SystemRoot%\System32\reg.exe" add "HKLM\SOFTWARE\Wow6432Node\Microsoft\WinHelp" /v "AllowProgrammaticMacros" /t REG_DWORD /d "0x00000001" /f >nul 2>&1
"%SystemRoot%\System32\reg.exe" add "HKLM\SOFTWARE\Wow6432Node\Microsoft\WinHelp" /v "AllowIntranetAccess" /t REG_DWORD /d "0x00000001" /f >nul 2>&1
)
echo Done.
goto :EXIT
:: ---------------------------------------------------------------------------
:: Error management
:COPYERROR
echo An error occurred while installing this file.
:ERROR
echo
pause
exit /b 1
:EXIT
exit /b 0