Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

280 lines
8.3 KiB

  1. setlocal ENABLEEXTENSIONS
  2. REM THis script runs on the target machine and does the following:
  3. REM 1. Copies a new version of FRS executable from a server hub machine if the
  4. REM current version matches the date and time of the old version to be replaced.
  5. REM 2. expands the new executable. (see variable name setup for "newexe" below.)
  6. REM 3. does a net stop ntfrs
  7. REM 4. does a regini to set FRS to do a non-auth restore on restart.
  8. REM 5. if a new FRS was copied in step 1 rename the current ntfrs.exe to a saved name
  9. REM 6. and copies the new executable to ntfrs.exe
  10. REM 7. does a net start ntfrs
  11. REM 8. copies the script log file to the hub machine with the name %computername%.log
  12. REM grep the log files for the string "QFE upgrade" to check the result status.
  13. REM
  14. REM WARNING: The rename/copy operation above must be modified to work with system file
  15. REM protection. I.E. the install part of this script currently does not work.
  16. REM
  17. REM Note: If a new version of FRS is not found on the hub machine this script will
  18. REM simply trigger a non-auth restore on the target computer.
  19. REM
  20. REM Note: This script can run unattended so you can use the AT command to launch it.
  21. REM
  22. REM AT \\<bch computer> <time> \\<path to this script on hub computer>
  23. REM e.g. AT \\branch1 15:05 \\hub1\update\frs_qfe\upgrfrs.cmd
  24. REM
  25. REM
  26. REM
  27. REM Update hub to the computer name of the hub machine
  28. REM Update hubinstalldir to the dir path where the images and tools can be found.
  29. REM This is also the dir where the script log file is written.
  30. REM
  31. set hub=DAVIDOR3
  32. set hubinstalldir=eer\temp\mma
  33. REM
  34. REM Update destlog to the location on the hub machine to put the script output log.
  35. REM
  36. set destlog=\\%hub%\%hubinstalldir%\
  37. REM
  38. REM frsqfe is the dir location on the hub machine where the qfe version of
  39. REM ntfrs.exe can be found.
  40. REM newexe is the file name of the new image. It should not be called ntfrs.exe
  41. REM and it is expected to be compressed so the file type is ASSUMED to be .ex_
  42. REM Use a command like "compress -z ntfrs.exe ntfrs_020100.ex_" to produced the
  43. REM compressed file on the hub server.
  44. REM savexe is the file name to which the current running ntfrs.exe is to be renamed.
  45. REM
  46. set newexe=ntfrs_020100
  47. set frsqfe=\\%hub%\%hubinstalldir%\%newexe%.ex_
  48. set savexe=ntfrs_win2k
  49. REM
  50. REM Supply the full path names for utils expand.exe and regini.exe to be used if no local version.
  51. REM
  52. set _copy_regini_=\\%hub%\%hubinstalldir%\regini.exe
  53. set _copy_expand_=\\%hub%\%hubinstalldir%\expand.exe
  54. REM
  55. REM Update this string to match the date format in your area.
  56. REM It should be the "dir" output of the version of ntfrs.exe that you are upgrading.
  57. REM This is the create time for the WIN2K version of ntfrs.
  58. REM
  59. set frsw2k="12/07/1999 05:35a 623,888 ntfrs.exe"
  60. set XCOPY_FLAGS=/R /Y /Z
  61. set out=%temp%\%computername%.log
  62. set stderror=%temp%\upgrfrs.err
  63. set stdout=%temp%\upgrfrs.out
  64. set noauth=%temp%\noauth.reg
  65. del %out%
  66. del %destlog%\%computername%.log
  67. set BNEWFRS=0
  68. REM
  69. REM ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
  70. REM
  71. echo ----- running on %computername% > %out%
  72. echo ----- %date% %time% >> %out%
  73. REM
  74. REM ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
  75. REM
  76. REM Check for temp dir and needed utilities.
  77. if NOT EXIST %TEMP% (
  78. echo ERROR -- Failed to find tempdir [%TEMP%] on %computername% quitting. >> %out%
  79. goto :QUIT
  80. )
  81. set _regini_=%windir%\system32\regini.exe
  82. if NOT EXIST !_regini_! (
  83. xcopy %_copy_regini_% %temp%\ %XCOPY_FLAGS% 1>>%out% 2>>%stderror%
  84. type %stderror% >> %out%
  85. set _regini_=%temp%\regini.exe
  86. if NOT EXIST !_regini_! (
  87. echo ERROR -- Failed to find regini.exe so non-auth restore will fail on %computername% quitting. >> %out%
  88. goto :QUIT
  89. )
  90. )
  91. set _expand_=%windir%\system32\expand.exe
  92. if NOT EXIST !_expand_! (
  93. xcopy %_copy_expand_% %temp%\ %XCOPY_FLAGS% 1>>%out% 2>>%stderror%
  94. type %stderror% >> %out%
  95. set _expand_=%temp%\expand.exe
  96. if NOT EXIST !_expand_! set _expand_=copy
  97. )
  98. REM
  99. REM ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
  100. REM
  101. pushd %windir%\system32
  102. dir ntfrs.exe > %stdout%
  103. type %stdout% >> %out%
  104. REM Check for WIN2K version of FRS
  105. findstr /c:%frsw2k% %stdout% >> %out%
  106. if NOT ERRORLEVEL 1 (
  107. REM Copy down the new ntfrs.exe
  108. xcopy %frsqfe% %newexe%.ex_ %XCOPY_FLAGS% 1>>%out% 2>%stderror%
  109. if ERRORLEVEL 1 (
  110. type %stderror% >> %out%
  111. xcopy %frsqfe% %newexe%.ex_ %XCOPY_FLAGS% 1>>%out% 2>%stderror%
  112. if ERRORLEVEL 1 (
  113. type %stderror% >> %out%
  114. xcopy %frsqfe% %newexe%.ex_ %XCOPY_FLAGS% 1>>%out% 2>%stderror%
  115. if ERRORLEVEL 1 (
  116. type %stderror% >> %out%
  117. echo ERROR -- Failed to copy FRS QFE %frsqfe% to %computername% >> %out%
  118. goto :STOP_FRS
  119. )
  120. )
  121. )
  122. echo ----- FRS QFE copy complete >> %out%
  123. echo ----- %date% %time% >> %out%
  124. !_expand_! %newexe%.ex_ %newexe%.exe 1>>%out% 2>%stderror%
  125. if %ERRORLEVEL% NEQ 0 (
  126. type %stderror% >> %out%
  127. echo ERROR -- Failed to expand FRS QFE %frsqfe% to %newexe% >> %out%
  128. goto :STOP_FRS
  129. )
  130. set BNEWFRS=1
  131. )
  132. REM
  133. REM ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
  134. REM
  135. :STOP_FRS
  136. echo ----- Stopping ntfrs service >> %out%
  137. net stop ntfrs 1>%stdout% 2>%stderror%
  138. if ERRORLEVEL 1 (
  139. type %stdout% >> %out%
  140. type %stderror% >> %out%
  141. REM
  142. REM just in case, try to stop it again.
  143. REM
  144. net stop ntfrs 1>%stdout% 2>%stderror%
  145. if ERRORLEVEL 1 (
  146. type %stdout% >> %out%
  147. type %stderror% >> %out%
  148. )
  149. )
  150. REM
  151. REM ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
  152. REM
  153. echo ----- Setting frs restart to non-auth restore. >> %out%
  154. echo HKEY_LOCAL_MACHINE\system\currentcontrolset\services\NtFrs\Parameters\Backup/Restore [17 1]> %noauth%
  155. echo Process at Startup [17 1]>>%noauth%
  156. echo BurFlags = REG_DWORD 0xd2>>%noauth%
  157. regini %noauth% 1>%stdout% 2>%stderror%
  158. if ERRORLEVEL 1 (
  159. type %stdout% >> %out%
  160. type %stderror% >> %out%
  161. echo ----- local regini failed. Trying version from hub.
  162. %_regini_% %noauth% >> %out%
  163. if ERRORLEVEL 1 (
  164. echo ----- Failed to set non-auth restore. Not restarting ntfrs service. >> %out%
  165. goto :QUIT
  166. )
  167. )
  168. echo ----- Success setting non-auth restore. >> %out%
  169. REM
  170. REM ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
  171. REM
  172. if !BNEWFRS! EQU 0 (
  173. echo ----- No new FRS copied so restarting existing version >> %out%
  174. set up_status=not
  175. goto :RESTART
  176. )
  177. echo ----- renaming ntfrs.exe >> %out%
  178. if EXIST %savexe%.exe del /F /Q %savexe%.exe
  179. ren ntfrs.exe %savexe%.exe 1>%stdout% 2>%stderror%
  180. if ERRORLEVEL 1 (
  181. echo ----- Failed to rename ntfrs.exe to %savexe%.exe >> %out%
  182. type %stdout% >> %out%
  183. type %stderror% >> %out%
  184. goto :QUIT
  185. )
  186. copy %newexe%.exe ntfrs.exe 1>%stdout% 2>%stderror%
  187. if ERRORLEVEL 1 (
  188. echo ----- Failed to copy %newexe%.exe to ntfrs.exe, restoring %savexe%.exe >> %out%
  189. type %stdout% >> %out%
  190. type %stderror% >> %out%
  191. ren %savexe%.exe ntfrs.exe 1>%stdout% 2>%stderror%
  192. goto :QUIT
  193. )
  194. :RESTART
  195. dir ntfrs*.exe >> %out%
  196. popd
  197. REM
  198. REM ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
  199. REM
  200. echo ----- Starting ntfrs service >> %out%
  201. net start ntfrs 1>%stdout% 2>%stderror%
  202. if ERRORLEVEL 1 (
  203. type %stdout% >> %out%
  204. type %stderror% >> %out%
  205. echo ----- Failed to restart ntfrs service. >> %out%
  206. goto :QUIT
  207. )
  208. REM
  209. REM ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
  210. REM
  211. echo ----- FRS QFE upgrade !up_status!completed for %computername% >> %out%
  212. :QUIT
  213. echo ----- %date% %time% >> %out%
  214. xcopy %out% %destlog% %XCOPY_FLAGS%
  215. del %stdout%
  216. del %stderror%
  217. del %noauth%