-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGenUpdates.cmd
238 lines (226 loc) · 9.12 KB
/
GenUpdates.cmd
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
231
232
233
234
235
236
237
238
:: by dialmak 25.10.2016
@echo off
pushd "%~dp0"
setlocal enableextensions enabledelayedexpansion
color 1f
set "ver=Generator CMD Scripts Updates v1.3"
echo %ver%
echo ----------------------------------
echo+
call :GetINI
call :ParseParam
set title=%ver% for folder %update_folder%
title %title%
pushd "%~dp0%update_folder%" && popd || (echo Žè¨¡ª . ¯ª "%~dp0%update_folder%" ¥ ©¤¥ . & goto :Exit)
dir "%update_folder%" /a:-d /b %sort_list% %sort_time% | findstr /i /e "%filter_ext%" > "%temp_list%" || (echo Žè¨¡ª . ” ©«ë ®¡®¢«¥¨© á à áè¨à¥¨ï¬¨ "%filter_ext%" ¥ ®¡ àã¦¥ë ¢ ¯ ¯ª¥ "%~dp0%update_folder%". & goto :Exit)
@echo off>"%filename_list%" || (echo Žè¨¡ª . ¥ ¯®«ãç ¥âáï ᮧ¤ âì ä ©« "%filename_list%". & goto :Exit)
for /f "usebackq delims=" %%A in ("%temp_list%") do echo "%%A">>"%filename_list%"
(
echo.
echo # Žâ। ªâ¨àã©â¥ íâ®â ᯨ᮪ ®¡®¢«¥¨© ¢ ⥪á⮢®¬ । ªâ®à¥.
echo # ®á«¥ । ªâ¨à®¢ ¨ï ¨ á®åà ¥¨ï í⮣® ᯨ᪠¢¥à¨â¥áì ¢ ®ª® áªà¨¯â .
echo # ‡ ⥬ ¦¬¨â¥ «î¡ãî ª« ¢¨èã ¨ áªà¨¯â áä®à¬¨àã¥â CMD ä ©« ¤«ï ¢ 襣® ᯨ᪠®¡®¢«¥¨©...
echo.
echo # ” ©« ¢ ᯨ᪥ ¤®«¦¥ ¡ëâì ®¡à ¬«¥ ¤¢®©ë¬¨ ª ¢ëçª ¬¨.
echo # „«ï ¯à®¯ã᪠§ ¯ãáª ä ©« - ¢ ç «¥ áâப¨ ¯®áâ ¢ì⥠à¥è¥âªã #.
echo # ® 㬮«ç ¨î ¨á¯®«ì§ãîâáï á«¥¤ãî騥 áâப¨ § ¯ã᪠:
echo # ¤«ï .msu ä ©«®¢ - start "" /wait wusa "filename.msu" /quiet /norestart
echo # ¤«ï ®áâ «ìëå ä ©«®¢ - start "" /wait "filename.ext" /quiet /norestart
echo.
echo # …᫨ âॡãîâáï ¤à㣨¥ ª«îç¨ § ¯ã᪠- ¯¨è¨â¥ ¨å ¯®á«¥ ¨¬¥¨ ä ©« ®¡®¢«¥¨©.
echo # …᫨ âॡã¥âáï § ¯ãáâ¨âì «î¡ãî ¯à®£à ¬¬ã - ¯¨è¨â¥ ¥ñ ¢ „‚Ž‰›• Š€‚›—Š€• ¯¥à¥¤ ¨¬¥¥¬ ä ©« ®¡®¢«¥¨©.
echo # ਬ¥àë.
echo # "IE11-Windows6.1-x64-en-us.exe" /x:"D:/IE11"
echo # "expand" -F:* "Windows6.1-KB3059317-x86.msu" "D:/My Updates"
echo.
)>>"%filename_list%"
echo ‘¯¨á®ª ®¡®¢«¥¨© áä®à¬¨à®¢ .
echo „«ï ç « । ªâ¨à®¢ ¨ï ä ©« á ᯨ᪮¬ ®¡®¢«¥¨© ¦¬¨â¥ «î¡ãî ª« ¢¨èã ...
pause > nul
echo+
start "" "%text_editor%" "%filename_list%"
ping 127.0.0.1 -n 3 > nul
echo „«ï ä®à¬¨à®¢ ¨ï CMD ä ©« ®¡®¢«¥¨© ¤«ï ¯ ¯ª¨ "%update_folder%" ¦¬¨â¥ «î¡ãî ª« ¢¨èã ...
pause > nul
call :Creator
start "" "%text_editor%" "%cmd_name%"
ping 127.0.0.1 -n 3 > nul
echo+
echo ‘ªà¨¯â § ª®ç¨« à ¡®âã.
:Exit
echo+
echo „«ï ¢ë室 ¦¬¨â¥ «î¡ãî ª« ¢¨èã ...
pause > nul
exit
:ParseParam
set "xOS=x64"
if /i "%PROCESSOR_ARCHITECTURE%"=="x86" if not defined PROCESSOR_ARCHITEW6432 set "xOS=x86"
set "temp_list=%temp%\temp_list_files.txt"
if not defined filename_list (set "filename_list=list_files_!date!.txt")
if not defined filter_ext (set "filter_ext= .msu .exe .cab .msi")
if not defined sort_list (set "sort_list=time")
if not defined sort_time (set "sort_time=3")
if not defined text_editor (
set "text_editor=%windir%\notepad.exe"
if exist "%ProgramFiles%\Notepad++\notepad++.exe" set "text_editor=%ProgramFiles%\Notepad++\notepad++.exe"
if exist "%ProgramFiles(x86)%\Notepad++\notepad++.exe" set "text_editor=%ProgramFiles(x86)%\Notepad++\notepad++.exe"
)
call :Trim update_folder %update_folder%
call :Trim filename_list %filename_list%
call :Trim filter_ext %filter_ext%
call :Trim sort_list %sort_list%
call :Trim text_editor %text_editor%
if defined update_folder if "!update_folder:~0,1!" equ "\" (set "update_folder=!update_folder:~1!")
if defined update_folder if "!update_folder:~-1!" equ "\" (set "update_folder=!update_folder:~,-1!")
if defined update_folder (set "filename_list=%~dp0%update_folder%\%filename_list%") else (set "filename_list=%~dp0%filename_list%")
if not defined update_folder (set "cmd_name=update_!date!.cmd")
if not defined cmd_name (
set "cmd_name=!update_folder: =_!"
set "cmd_name=!cmd_name:\=_!_!date!.cmd"
)
echo update_folder=%update_folder%
rem echo text_editor=%text_editor%
echo cmd_name=%cmd_name%
echo filter_ext=%filter_ext%
echo sort_list=%sort_list%
echo+
if /i "%sort_time%" EQU "1" (set "sort_time=/t:c")
if /i "%sort_time%" EQU "2" (set "sort_time=/t:a")
if /i "%sort_time%" EQU "3" (set "sort_time=/t:w")
if /i "%sort_list%" EQU "abc" (set "sort_time=")
if /i "%sort_list%" EQU "-abc"(set "sort_time=")
if /i "%sort_list%" EQU "time" (set "sort_list=/o:d")
if /i "%sort_list%" EQU "-time" (set "sort_list=/o:-d")
if /i "%sort_list%" EQU "abc" (set "sort_list=/o:n")
if /i "%sort_list%" EQU "-abc" (set "sort_list=/o:-n")
set "cmd_name=%~dp0!cmd_name!"
exit /b
:Trim
setlocal enabledelayedexpansion
set params=%*
if %params:~0,1% EQU [ endlocal & exit /b
for /f "tokens=1*" %%A in ("!params!") do (endlocal & set "%1=%%~B")
exit /b
:GetINI
set "INIFile=%~dp0settings.ini"
if exist "%INIFile%" (
cmd /c type "%INIFile%">"%temp%\settings.ini"
for /f "eol=# skip=1 usebackq tokens=1,2* delims==" %%I in ("%temp%\settings.ini") do (call :Trim %%~I %%~J)
) else (
echo Žè¨¡ª . ” ©« áâ஥ª ¯ à ¬¥â஢ "%INIFile%" ¥ ©¤¥.
goto :Exit
)
exit /b
:Creator
(
echo @echo off
echo setlocal enableextensions enabledelayedexpansion
echo color 1F
echo pushd="%%~dp0%update_folder%"
echo set "xOS=x64"
echo if /i "%%PROCESSOR_ARCHITECTURE%%"=="x86" if not defined PROCESSOR_ARCHITEW6432 set "xOS=x86"
echo call :en-US
echo set langkey="HKLM\SYSTEM\CurrentControlSet\Control\Nls\Language"
echo for /f "tokens=3 delims= " %%%%A in ^('reg query %%langkey%% /v InstallLanguage 2^^^>nul'^) do ^(if %%%%A EQU 0419 call :ru-RU^)
echo set title=%%mes01%% "%update_folder%"
echo title %%title%%
echo set /a num=0
echo set /a err=0
echo call :GetAdminRights
echo echo.
echo echo %%title%%
echo echo+ ------------------------------------------------------------------------------
for /f eol^=#^ usebackq^ tokens^=1^,*^ delims^=^" %%A in ("%filename_list%") do (
if /i [%%B] NEQ [] if /i [%%~xA] EQU [.msu] (
set /a num+=1
echo echo+ !num!. %%mes02%% "%%~A" ...
echo start "" /wait wusa "%%~A" %%B
echo call :GetErrorCode)
if /i [%%B] EQU [] if /i [%%~xA] EQU [.msu] (
set /a num+=1
echo echo+ !num!. %%mes02%% "%%~A" ...
echo start "" /wait wusa "%%~A" /quiet /norestart
echo call :GetErrorCode)
if /i [%%B] NEQ [] if /i [%%~xA] NEQ [.msu] (
set /a num+=1
echo echo+ !num!. %%mes02%% "%%~A" ...
echo start "" /wait "%%~A" %%B
echo call :GetErrorCode)
if /i [%%B] EQU [] if /i [%%~xA] NEQ [.msu] (
set /a num+=1
echo echo+ !num!. %%mes02%% "%%~A" ...
echo start "" /wait "%%~A" /quiet /norestart
echo call :GetErrorCode)
)
echo echo+ ------------------------------------------------------------------------------
echo+
echo set /a inst=%%num%%-%%err%%
echo echo+ %%mes03%% = %%inst%%
echo echo+ %%mes04%% = %%err%%
echo echo+ %%mes05%% = %%num%%
echo echo.
echo echo+ %%mes06%%
echo pause ^> nul
echo popd
echo exit
echo+
echo :GetAdminRights
echo reg.exe query "HKU\S-1-5-19" ^>nul 2^>^&1 ^|^| ^(
echo echo Set UAC = CreateObject^^^("Shell.Application"^^^) ^> "%%temp%%\GetAdmin.vbs"
echo echo UAC.ShellExecute "%%~f0", "", "", "runas", 1 ^>^> "%%temp%%\GetAdmin.vbs"
echo %%ComSpec%% /u /c type "%%temp%%\GetAdmin.vbs" ^> "%%temp%%\GetAdminUnicode.vbs"
echo %%windir%%\system32\cscript //nologo "%%temp%%\GetAdminUnicode.vbs"
echo del /f /q "%%temp%%\GetAdmin.vbs" ^> nul 2^>^&1
echo del /f /q "%%temp%%\GetAdminUnicode.vbs" ^> nul 2^>^&1
echo exit
echo ^)
echo exit /b
echo+
echo :GetErrorCode
echo call :DecToHex %%errorlevel%% hexval
echo set /a num+=1
echo if %%hexval%% EQU 0x00000000 ^(echo %%mes07%% ^^^(%%hexval%%^^^) ^& exit ^/b^)
echo if %%hexval%% EQU 0x00000BC2 ^(echo %%mes08%% ^^^(%%hexval%%^^^) ^& exit /b^)
echo if %%hexval%% EQU 0x00009C48 ^(echo %%mes09%% ^^^(%%hexval%%^^^)^&set /a err+=1 ^& exit /b^)
echo if %%hexval%% EQU 0x00240006 ^(echo %%mes09%% ^^^(%%hexval%%^^^)^&set /a err+=1 ^& exit /b^)
echo if %%hexval%% EQU 0x80240017 ^(echo %%mes10%% ^^^(%%hexval%%^^^)^&set /a err+=1 ^& exit /b^)
echo if %%hexval%% EQU 0x00000002 ^(echo %%mes11%% ^^^(%%hexval%%^^^)^&set /a err+=1 ^& exit /b^)
echo echo %%mes12%% ^^^(%%hexval%%^^^) ^& set /a err+=1
echo exit /b
echo+
echo :DecToHex
echo call %%ComSpec%% /c exit /b %%~1
echo set hexval=%%=exitcode%%
echo set "%%~2=0x%%hexval%%"
echo exit /b
echo+
echo :ru-Ru
echo set "mes01=“áâ ®¢ª ®¡®¢«¥¨© Windows ¤«ï ¯ ¯ª¨"
echo set "mes02=ˆáâ ««ïæ¨ï"
echo set "mes03=“ᯥè®"
echo set "mes04=Žè¨¡®ª "
echo set "mes05=‚ᥣ® "
echo set "mes06=¥à¥§ £à㧨⥠᢮© ª®¬¯ìîâ¥à ¤«ï § ¢¥àè¥¨ï ¨áâ ««ï樨 ®¡®¢«¥¨© ..."
echo set "mes07=Ž¡®¢«¥¨¥ ãáâ ®¢«¥®"
echo set "mes08=Ž¡®¢«¥¨¥ ãáâ ®¢«¥®, âॡã¥âáï ¯¥à¥£à㧪 "
echo set "mes09=“áâ ®¢ª í⮣® ®¡®¢«¥¨ï ¡ë« ¢ë¯®«¥ à ¥¥"
echo set "mes10=Ž¡®¢«¥¨¥ ¥¯à¨¬¥¨¬® ª í⮬㠪®¬¯ìîâ¥àã"
echo set "mes11=” ©« ®¡®¢«¥¨ï ¥ ©¤¥"
echo set "mes12=Žè¨¡ª ãáâ ®¢ª¨ ®¡®¢«¥¨ï"
echo exit /b
echo :en-US
echo set "mes01=Install Updates for Windows for folder"
echo set "mes02=Installing"
echo set "mes03=Success"
echo set "mes04=Error "
echo set "mes05=All "
echo set "mes06=Please reboot your computer to complete installation ..."
echo set "mes07=Installation completed successfully"
echo set "mes08=The system must be restarted to complete installation of the update"
echo set "mes09=The update to be installed is already installed on the system"
echo set "mes10=The update does not apply to this computer"
echo set "mes11=The update file is not found"
echo set "mes12=Error updating"
echo exit /b
) > "%cmd_name%"
exit /b