Advertisement
Guest User

Untitled

a guest
Feb 21st, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.93 KB | None | 0 0
  1. @ECHO OFF
  2.  
  3. ::==============================::
  4. :: SteamCMD Auto Updater 1.7 ::
  5. :: Credits ::
  6. :: C0nw0nk ::
  7. ::==============================::
  8. :: https://github.com/C0nw0nk/SteamCMD-AutoUpdate-Any-Gameserver ::
  9.  
  10. :: This is the SteamDEV api key required for automatic updates ::
  11. :: If you do not have one you may obtain your API key from here = http://steamcommunity.com/dev/apikey ::
  12. set steamkey=mykeyhere
  13.  
  14. :: This is the required login for SteamCMD to download updates ::
  15. :: example = login=C0nw0nk Password ::
  16. :: For most game servers you do not require this and can leave it as anonymous ::
  17. :: Certain game servers you have to use a username and password to install them ::
  18. set login=name password
  19.  
  20. :: This is the directory you wish to install and keep your server updated to ::
  21. set install_directory=C:\BRAINZ1\
  22.  
  23. :: This is for the directory where you installed steamcmd ::
  24. :: http://media.steampowered.com/installer/steamcmd.zip ::
  25. set steamcmd_path=C:\steamcmd\steamcmd.exe
  26.  
  27. :: This is the path to the exe of the game server this allows us to close and run the server for and after a update ::
  28. :: Other command line variables for srcds can be found here https://developer.valvesoftware.com/wiki/Command_Line_Options ::
  29. :: Example ::
  30. :: set exe_path=C:\game-servers\CSGO\srcds.exe -game csgo -console -nocrashdialog -port 27015 +clientport 27005 +map de_dust2 ::
  31. set exe_path=C:\BRAINZ1\Unturned.exe -nographics -batchmode -silent-crashes +secureserver/BRAINZ1
  32.  
  33. :: This is the title of your server this will help you know what server this auto updater is running for ::
  34. set servername=BRAINZ1
  35.  
  36. :: This is the app ID of the game server you are installing / running ::
  37. set appid=304930
  38.  
  39. :: This is the app ID the url will check for updates on that game ::
  40. :: Some games this is the same as the installation appid other games it is a different numeric value ::
  41. :: if your latest-version.txt file is empty you need to make this value different to the installation appid, just go to the steam store page and get the appid from the end url ::
  42. set update_appid=304930
  43.  
  44. :: Automatic Updating Interval (in seconds) this will set how often you check the steam servers for a new update ::
  45. :: I recommend 5-10 mins maximum ::
  46. :: Default value 60 seconds 1 minute ::
  47. set interval=120
  48.  
  49. :: Suppress application error messages, Usualy when your game server crashes you get flagged the following error ::
  50. :: "srcds.exe has stopped working. Windows can check online for a solution to the problem" ::
  51. :: and even after disabling error reporting and the message above you will get the following message instead ::
  52. :: "srcds.exe has stopped working. A problem caused the program to stop working correctly. Please close the program" ::
  53. :: With the following setting the script will prevent all these errors and get your server back online as soon as a crash occurs ::
  54. :: set to false to disable this feature ::
  55. :: Use -nocrashdialog in exe_path to also help suppress server crashes ::
  56. set suppress_errors=true
  57.  
  58. :: Don't edit anything past this point ::
  59.  
  60. :: I AM SERIOUS DO NOT TOUCH ::
  61.  
  62. :: DON'T MAKE ME HURT YOU! ::
  63.  
  64. :: il fite u ::
  65.  
  66. :: Do you realy want some! ::
  67.  
  68. :: Come on don't be a skrub! ::
  69.  
  70. :: Sorry did not mean anything I just said go ahead and edit below this point see if I care (seriously just don't touch anything below this)::
  71.  
  72. :: for the fact you have even scrolled down this far shows your persistence ::
  73.  
  74. title %servername% SteamCMD Auto Updater V1.7
  75.  
  76. rem set window and text color
  77. color 8a
  78.  
  79. setlocal enableDelayedExpansion
  80.  
  81.  
  82. echo [%time%] Untu
  83.  
  84.  
  85. if "%suppress_errors%"=="false" (
  86. reg add "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Windows" /v ErrorMode /t REG_DWORD /d 0 /f >nul 2>&1
  87. reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\Windows Error Reporting" /v DontShowUI /t REG_DWORD /d 0 /f >nul 2>&1
  88. ) else (
  89. reg add "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Windows" /v ErrorMode /t REG_DWORD /d 2 /f >nul 2>&1
  90. reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\Windows Error Reporting" /v DontShowUI /t REG_DWORD /d 1 /f >nul 2>&1
  91. )
  92.  
  93. FOR /f %%i IN ("%install_directory%") DO (
  94. set filedrive=%%~di
  95. set filepath=%%~pi
  96. set filename=%%~ni
  97. set fileextension=%%~xi
  98. )
  99. if exist %filedrive%%filepath%%filename% (
  100. echo file path exist >nul
  101. ) else (
  102. echo create install_directory since it does not exist
  103. mkdir %filedrive%%filepath%%filename%
  104. )
  105.  
  106.  
  107. FOR /f %%i IN ("%steamcmd_path%") DO (
  108. set filedrive=%%~di
  109. set filepath=%%~pi
  110. set filename=%%~ni
  111. set fileextension=%%~xi
  112. )
  113. set downloadurl=http://media.steampowered.com/installer/steamcmd.zip
  114. set downloadpath=%filedrive%%filepath%steamcmd.zip
  115. if exist %filedrive%%filepath%%filename%%fileextension% (
  116. echo file path exist >nul
  117. ) else (
  118. echo create steamcmd_path since it does not exist
  119. mkdir %filedrive%%filepath%
  120. (
  121. echo Dim oXMLHTTP
  122. echo Dim oStream
  123. echo Set oXMLHTTP = CreateObject^("MSXML2.XMLHTTP.3.0"^)
  124. echo oXMLHTTP.Open "GET", "%downloadurl%", False
  125. echo oXMLHTTP.Send
  126. echo If oXMLHTTP.Status = 200 Then
  127. echo Set oStream = CreateObject^("ADODB.Stream"^)
  128. echo oStream.Open
  129. echo oStream.Type = 1
  130. echo oStream.Write oXMLHTTP.responseBody
  131. echo oStream.SaveToFile "%downloadpath%"
  132. echo oStream.Close
  133. echo End If
  134. echo ZipFile="%downloadpath%"
  135. echo ExtractTo="%filedrive%%filepath%"
  136. echo Set fso = CreateObject^("Scripting.FileSystemObject"^)
  137. echo If NOT fso.FolderExists^(ExtractTo^) Then
  138. echo fso.CreateFolder^(ExtractTo^)
  139. echo End If
  140. echo set objShell = CreateObject^("Shell.Application"^)
  141. echo set FilesInZip=objShell.NameSpace^(ZipFile^).items
  142. echo objShell.NameSpace^(ExtractTo^).CopyHere^(FilesInZip^)
  143. echo Set fso = Nothing
  144. echo Set objShell = Nothing
  145. )>>"%~n0-temp.vbs"
  146. cscript //nologo %~n0-temp.vbs & del %~n0-temp.vbs
  147. )
  148.  
  149. goto error
  150. :loop
  151.  
  152. if exist %~n0-latest-version.txt (
  153. rem echo file exist so do nothing and perform file check to compare existing files
  154. del %~n0-latest-version.txt
  155. )
  156. (
  157. echo Dim oXMLHTTP
  158. echo Dim oStream
  159. echo Set oXMLHTTP = CreateObject^("MSXML2.XMLHTTP.3.0"^)
  160. echo oXMLHTTP.Open "GET", "http://api.steampowered.com/ISteamUserStats/GetSchemaForGame/v2/?key=%steamkey%&appid=%update_appid%&format=json", False
  161. echo oXMLHTTP.Send
  162. echo If oXMLHTTP.Status = 200 Then
  163. echo Set oStream = CreateObject^("ADODB.Stream"^)
  164. echo oStream.Open
  165. echo oStream.Type = 1
  166. echo oStream.Write oXMLHTTP.responseBody
  167. echo oStream.SaveToFile "%~n0-latest-version.txt"
  168. echo oStream.Close
  169. echo End If
  170. )>>"%~n0-temp.vbs"
  171. cscript //nologo %~n0-temp.vbs & del %~n0-temp.vbs
  172.  
  173. rem call to get the latest game server version from the steam servers
  174.  
  175. if exist %~n0-current-version.txt (
  176. rem echo file exist so do nothing and perform file check to compare existing files
  177. echo "" >nul
  178. ) else (
  179. rem echo file doesn't exist so create it and update / install the game server to the latest version
  180. COPY %~n0-latest-version.txt %~n0-current-version.txt
  181. goto error
  182. )
  183. rem file check compare the latest game server version with the current and if they match or miss match
  184. fc %~n0-latest-version.txt %~n0-current-version.txt >nul
  185. if errorlevel 1 goto shutdown_server
  186. :next
  187. rem echo file version match with currently installed so do nothing and attempt to start the server if not already running
  188. rem get the running game server process id from our pid file
  189. set /p texte=< %~n0-pid.txt
  190. rem echo %texte%
  191. rem use the process id and check if it is running or not
  192. rem find process id of game server that should be running and if status is not responding or unknown it means the server has crashed
  193. set "cmd2=tasklist.exe /fi "pid eq %texte%" /fi "status ne running""
  194. for /F "delims=*" %%p in ('!cmd2! ^| findstr "%texte%" ') do (
  195. rem echo pid running but frozen or not responding so terminate
  196. taskkill /PID %texte%
  197. goto next
  198. )
  199. rem check process id to see if running and active
  200. set "cmd=tasklist.exe /FI "pid eq %texte%""
  201. for /F "delims=*" %%p in ('!cmd! ^| findstr "%texte%" ') do (
  202. rem echo pid running and found %%p
  203. timeout /t %interval% /NOBREAK
  204. goto loop
  205. )
  206. rem echo pid not found pause so start running the game server and get game server pid
  207. rem process id in pid file not found or running so lets start the game server to get it running and store the game server pid in the file
  208. for /f "tokens=2 delims==; " %%a in (' wmic process call create "%exe_path%"^,"%cd%" ^| find "ProcessId" ') do set PID=%%a
  209. echo %PID% > %~n0-pid.txt
  210. timeout /t %interval% /NOBREAK
  211. goto loop
  212. pause
  213. :error
  214. rem echo failed check so execute steamcmd to update / install the server
  215. rem First we have to kill the running game server pid in order to update it
  216. rem get the running game server process id from our pid file
  217. set /p texte=< %~n0-pid.txt
  218. rem echo %texte%
  219. rem use the process id and check if it is running or not
  220. set "cmd=tasklist.exe /FI "pid eq %texte%""
  221. for /F "delims=*" %%p in ('!cmd! ^| findstr "%texte%" ') do (
  222. rem echo pid of game server running and found so kill / end the process %%p
  223. taskkill /PID %texte%
  224. )
  225. rem execute updater and then close when updates installed and validated
  226. %steamcmd_path% +login %login% +force_install_dir %install_directory% +app_update %appid% +quit
  227. rem when update complete go back to the start and check for updates on a regular basis again and launch the updated game server
  228. rem we cant forget to set the current version to the latest installed version
  229. COPY %~n0-latest-version.txt %~n0-current-version.txt >nul
  230. goto loop
  231. pause
  232. :shutdown_server
  233. set /p texte=< %~n0-pid.txt
  234. set "cmd=tasklist.exe /FI "pid eq %texte%""
  235. for /F "delims=*" %%p in ('!cmd! ^| findstr "%texte%" ') do (goto :console_vbs1)
  236. :console_vbs1
  237. echo Option Explicit >%~n0-temp.vbs
  238. echo Dim Shell, WMI, wql, process >>%~n0-temp.vbs
  239. echo Set Shell = CreateObject("WScript.Shell") >>%~n0-temp.vbs
  240. echo Set WMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") >>%~n0-temp.vbs
  241. echo wql = "SELECT ProcessId FROM Win32_Process WHERE ProcessId = %texte%" >>%~n0-temp.vbs
  242. echo For Each process In WMI.ExecQuery(wql) >>%~n0-temp.vbs
  243. echo Shell.AppActivate process.ProcessId >>%~n0-temp.vbs
  244. echo Shell.SendKeys 'say "Server will shut down in 60 seconds for updates!"' >>%~n0-temp.vbs
  245. echo Shell.SendKeys "{ENTER}" >>%~n0-temp.vbs
  246. echo Next >>%~n0-temp.vbs
  247. cscript //nologo %~n0-temp.vbs & del %~n0-temp.vbs
  248. timeout /t 30 /NOBREAK
  249. goto :console_vbs2
  250. :console_vbs2
  251. echo Option Explicit >%~n0-temp.vbs
  252. echo Dim Shell, WMI, wql, process >>%~n0-temp.vbs
  253. echo Set Shell = CreateObject("WScript.Shell") >>%~n0-temp.vbs
  254. echo Set WMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") >>%~n0-temp.vbs
  255. echo wql = "SELECT ProcessId FROM Win32_Process WHERE ProcessId = %texte%" >>%~n0-temp.vbs
  256. echo For Each process In WMI.ExecQuery(wql) >>%~n0-temp.vbs
  257. echo Shell.AppActivate process.ProcessId >>%~n0-temp.vbs
  258. echo Shell.SendKeys 'say "Server will shut down in 30 seconds for updates!"' >>%~n0-temp.vbs
  259. echo Shell.SendKeys "{ENTER}" >>%~n0-temp.vbs
  260. echo Next >>%~n0-temp.vbs
  261. cscript //nologo %~n0-temp.vbs & del %~n0-temp.vbs
  262. timeout /t 20 /NOBREAK
  263. goto :console_vbs3
  264. :console_vbs3
  265. echo Option Explicit >%~n0-temp.vbs
  266. echo Dim Shell, WMI, wql, process >>%~n0-temp.vbs
  267. echo Set Shell = CreateObject("WScript.Shell") >>%~n0-temp.vbs
  268. echo Set WMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") >>%~n0-temp.vbs
  269. echo wql = "SELECT ProcessId FROM Win32_Process WHERE ProcessId = %texte%" >>%~n0-temp.vbs
  270. echo For Each process In WMI.ExecQuery(wql) >>%~n0-temp.vbs
  271. echo Shell.AppActivate process.ProcessId >>%~n0-temp.vbs
  272. echo Shell.SendKeys 'say "Server will shut down in 10 seconds for updates!"' >>%~n0-temp.vbs
  273. echo Shell.SendKeys "{ENTER}" >>%~n0-temp.vbs
  274. echo Next >>%~n0-temp.vbs
  275. cscript //nologo %~n0-temp.vbs & del %~n0-temp.vbs
  276. timeout /t 1 /NOBREAK
  277. goto :console_vbs4
  278. :console_vbs4
  279. echo Option Explicit >%~n0-temp.vbs
  280. echo Dim Shell, WMI, wql, process >>%~n0-temp.vbs
  281. echo Set Shell = CreateObject("WScript.Shell") >>%~n0-temp.vbs
  282. echo Set WMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") >>%~n0-temp.vbs
  283. echo wql = "SELECT ProcessId FROM Win32_Process WHERE ProcessId = %texte%" >>%~n0-temp.vbs
  284. echo For Each process In WMI.ExecQuery(wql) >>%~n0-temp.vbs
  285. echo Shell.AppActivate process.ProcessId >>%~n0-temp.vbs
  286. echo Shell.SendKeys 'say "Server will shut down in 9 seconds for updates!"' >>%~n0-temp.vbs
  287. echo Shell.SendKeys "{ENTER}" >>%~n0-temp.vbs
  288. echo Next >>%~n0-temp.vbs
  289. cscript //nologo %~n0-temp.vbs & del %~n0-temp.vbs
  290. timeout /t 1 /NOBREAK
  291. goto :console_vbs5
  292. :console_vbs5
  293. echo Option Explicit >%~n0-temp.vbs
  294. echo Dim Shell, WMI, wql, process >>%~n0-temp.vbs
  295. echo Set Shell = CreateObject("WScript.Shell") >>%~n0-temp.vbs
  296. echo Set WMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") >>%~n0-temp.vbs
  297. echo wql = "SELECT ProcessId FROM Win32_Process WHERE ProcessId = %texte%" >>%~n0-temp.vbs
  298. echo For Each process In WMI.ExecQuery(wql) >>%~n0-temp.vbs
  299. echo Shell.AppActivate process.ProcessId >>%~n0-temp.vbs
  300. echo Shell.SendKeys 'say "Server will shut down in 8 seconds for updates!"' >>%~n0-temp.vbs
  301. echo Shell.SendKeys "{ENTER}" >>%~n0-temp.vbs
  302. echo Next >>%~n0-temp.vbs
  303. cscript //nologo %~n0-temp.vbs & del %~n0-temp.vbs
  304. timeout /t 1 /NOBREAK
  305. goto :console_vbs6
  306. :console_vbs6
  307. echo Option Explicit >%~n0-temp.vbs
  308. echo Dim Shell, WMI, wql, process >>%~n0-temp.vbs
  309. echo Set Shell = CreateObject("WScript.Shell") >>%~n0-temp.vbs
  310. echo Set WMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") >>%~n0-temp.vbs
  311. echo wql = "SELECT ProcessId FROM Win32_Process WHERE ProcessId = %texte%" >>%~n0-temp.vbs
  312. echo For Each process In WMI.ExecQuery(wql) >>%~n0-temp.vbs
  313. echo Shell.AppActivate process.ProcessId >>%~n0-temp.vbs
  314. echo Shell.SendKeys 'say "Server will shut down in 7 seconds for updates!"' >>%~n0-temp.vbs
  315. echo Shell.SendKeys "{ENTER}" >>%~n0-temp.vbs
  316. echo Next >>%~n0-temp.vbs
  317. cscript //nologo %~n0-temp.vbs & del %~n0-temp.vbs
  318. timeout /t 1 /NOBREAK
  319. goto :console_vbs7
  320. :console_vbs7
  321. echo Option Explicit >%~n0-temp.vbs
  322. echo Dim Shell, WMI, wql, process >>%~n0-temp.vbs
  323. echo Set Shell = CreateObject("WScript.Shell") >>%~n0-temp.vbs
  324. echo Set WMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") >>%~n0-temp.vbs
  325. echo wql = "SELECT ProcessId FROM Win32_Process WHERE ProcessId = %texte%" >>%~n0-temp.vbs
  326. echo For Each process In WMI.ExecQuery(wql) >>%~n0-temp.vbs
  327. echo Shell.AppActivate process.ProcessId >>%~n0-temp.vbs
  328. echo Shell.SendKeys 'say "Server will shut down in 6 seconds for updates!"' >>%~n0-temp.vbs
  329. echo Shell.SendKeys "{ENTER}" >>%~n0-temp.vbs
  330. echo Next >>%~n0-temp.vbs
  331. cscript //nologo %~n0-temp.vbs & del %~n0-temp.vbs
  332. timeout /t 1 /NOBREAK
  333. goto :console_vbs8
  334. :console_vbs8
  335. echo Option Explicit >%~n0-temp.vbs
  336. echo Dim Shell, WMI, wql, process >>%~n0-temp.vbs
  337. echo Set Shell = CreateObject("WScript.Shell") >>%~n0-temp.vbs
  338. echo Set WMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") >>%~n0-temp.vbs
  339. echo wql = "SELECT ProcessId FROM Win32_Process WHERE ProcessId = %texte%" >>%~n0-temp.vbs
  340. echo For Each process In WMI.ExecQuery(wql) >>%~n0-temp.vbs
  341. echo Shell.AppActivate process.ProcessId >>%~n0-temp.vbs
  342. echo Shell.SendKeys 'say "Server will shut down in 5 seconds for updates!"' >>%~n0-temp.vbs
  343. echo Shell.SendKeys "{ENTER}" >>%~n0-temp.vbs
  344. echo Next >>%~n0-temp.vbs
  345. cscript //nologo %~n0-temp.vbs & del %~n0-temp.vbs
  346. timeout /t 1 /NOBREAK
  347. goto :console_vbs9
  348. :console_vbs9
  349. echo Option Explicit >%~n0-temp.vbs
  350. echo Dim Shell, WMI, wql, process >>%~n0-temp.vbs
  351. echo Set Shell = CreateObject("WScript.Shell") >>%~n0-temp.vbs
  352. echo Set WMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") >>%~n0-temp.vbs
  353. echo wql = "SELECT ProcessId FROM Win32_Process WHERE ProcessId = %texte%" >>%~n0-temp.vbs
  354. echo For Each process In WMI.ExecQuery(wql) >>%~n0-temp.vbs
  355. echo Shell.AppActivate process.ProcessId >>%~n0-temp.vbs
  356. echo Shell.SendKeys 'say "Server will shut down in 4 seconds for updates!"' >>%~n0-temp.vbs
  357. echo Shell.SendKeys "{ENTER}" >>%~n0-temp.vbs
  358. echo Next >>%~n0-temp.vbs
  359. cscript //nologo %~n0-temp.vbs & del %~n0-temp.vbs
  360. timeout /t 1 /NOBREAK
  361. goto :console_vbs10
  362. :console_vbs10
  363. echo Option Explicit >%~n0-temp.vbs
  364. echo Dim Shell, WMI, wql, process >>%~n0-temp.vbs
  365. echo Set Shell = CreateObject("WScript.Shell") >>%~n0-temp.vbs
  366. echo Set WMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") >>%~n0-temp.vbs
  367. echo wql = "SELECT ProcessId FROM Win32_Process WHERE ProcessId = %texte%" >>%~n0-temp.vbs
  368. echo For Each process In WMI.ExecQuery(wql) >>%~n0-temp.vbs
  369. echo Shell.AppActivate process.ProcessId >>%~n0-temp.vbs
  370. echo Shell.SendKeys 'say "Server will shut down in 3 seconds for updates!"'>>%~n0-temp.vbs
  371. echo Shell.SendKeys "{ENTER}" >>%~n0-temp.vbs
  372. echo Next >>%~n0-temp.vbs
  373. cscript //nologo %~n0-temp.vbs & del %~n0-temp.vbs
  374. timeout /t 1 /NOBREAK
  375. goto :console_vbs11
  376. :console_vbs11
  377. echo Option Explicit >%~n0-temp.vbs
  378. echo Dim Shell, WMI, wql, process >>%~n0-temp.vbs
  379. echo Set Shell = CreateObject("WScript.Shell") >>%~n0-temp.vbs
  380. echo Set WMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") >>%~n0-temp.vbs
  381. echo wql = "SELECT ProcessId FROM Win32_Process WHERE ProcessId = %texte%" >>%~n0-temp.vbs
  382. echo For Each process In WMI.ExecQuery(wql) >>%~n0-temp.vbs
  383. echo Shell.AppActivate process.ProcessId >>%~n0-temp.vbs
  384. echo Shell.SendKeys 'say "Server will shut down in 2 seconds for updates!"' >>%~n0-temp.vbs
  385. echo Shell.SendKeys "{ENTER}" >>%~n0-temp.vbs
  386. echo Next >>%~n0-temp.vbs
  387. cscript //nologo %~n0-temp.vbs & del %~n0-temp.vbs
  388. timeout /t 1 /NOBREAK
  389. goto :console_vbs12
  390. :console_vbs12
  391. echo Option Explicit >%~n0-temp.vbs
  392. echo Dim Shell, WMI, wql, process >>%~n0-temp.vbs
  393. echo Set Shell = CreateObject("WScript.Shell") >>%~n0-temp.vbs
  394. echo Set WMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") >>%~n0-temp.vbs
  395. echo wql = "SELECT ProcessId FROM Win32_Process WHERE ProcessId = %texte%" >>%~n0-temp.vbs
  396. echo For Each process In WMI.ExecQuery(wql) >>%~n0-temp.vbs
  397. echo Shell.AppActivate process.ProcessId >>%~n0-temp.vbs
  398. echo Shell.SendKeys 'say "Server will shut down in 1 second for updates!"' >>%~n0-temp.vbs
  399. echo Shell.SendKeys "{ENTER}" >>%~n0-temp.vbs
  400. echo Next >>%~n0-temp.vbs
  401. cscript //nologo %~n0-temp.vbs & del %~n0-temp.vbs
  402. timeout /t 1 /NOBREAK
  403. goto :console_vbs13
  404. :console_vbs13
  405. echo Option Explicit >%~n0-temp.vbs
  406. echo Dim Shell, WMI, wql, process >>%~n0-temp.vbs
  407. echo Set Shell = CreateObject("WScript.Shell") >>%~n0-temp.vbs
  408. echo Set WMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") >>%~n0-temp.vbs
  409. echo wql = "SELECT ProcessId FROM Win32_Process WHERE ProcessId = %texte%" >>%~n0-temp.vbs
  410. echo For Each process In WMI.ExecQuery(wql) >>%~n0-temp.vbs
  411. echo Shell.AppActivate process.ProcessId >>%~n0-temp.vbs
  412. echo Shell.SendKeys "say 'Server is shutting down to install updates, Goodbye!"' >>%~n0-temp.vbs
  413. echo Shell.SendKeys "{ENTER}" >>%~n0-temp.vbs
  414. echo Next >>%~n0-temp.vbs
  415. cscript //nologo %~n0-temp.vbs & del %~n0-temp.vbs
  416. goto :error
  417. pause
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement