Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for bkviddrv.rex

(view source code of bkviddrv.rex as plain text)

  1. /* Backup video adapter driver files with DEVCON */
  2.  
  3. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  4. /* Sample DEVCON output:                                                               */
  5. /*                                                                                     */
  6. /* PCI\VEN_10DE&DEV_0110&SUBSYS_40311043&REV_B2\4&252D6E8&0&0008                       */
  7. /*    Name: NVIDIA GeForce2 MX                                                         */
  8. /*    Driver installed from c:\winnt\inf\oem29.inf [nv4]. 21 file(s) used by driver:   */
  9. /*        C:\WINNT\system32\DRIVERS\nv4_mini.sys                                       */
  10. /*        C:\WINNT\system32\nvinstnt.dll                                               */
  11. /*        C:\WINNT\system32\nvsvc32.exe                                                */
  12. /*        C:\WINNT\system32\nvcod.dll                                                  */
  13. /*        C:\WINNT\system32\nv4_disp.dll                                               */
  14. /*        C:\WINNT\system32\nvoglnt.dll                                                */
  15. /*        C:\WINNT\system32\nvcpl.dll                                                  */
  16. /*        C:\WINNT\system32\nvmctray.dll                                               */
  17. /*        C:\WINNT\system32\nview.dll                                                  */
  18. /*        C:\WINNT\system32\nvwddi.dll                                                 */
  19. /*        C:\WINNT\system32\nvappbar.exe                                               */
  20. /*        C:\WINNT\system32\nvwdmcpl.dll                                               */
  21. /*        C:\WINNT\system32\nvshell.dll                                                */
  22. /*        C:\WINNT\system32\nvtuicpl.cpl                                               */
  23. /*        C:\WINNT\system32\nwiz.exe                                                   */
  24. /*        C:\WINNT\system32\nviewimg.dll                                               */
  25. /*        C:\WINNT\system32\keystone.exe                                               */
  26. /*        C:\WINNT\system32\nvnt4cpl.dll                                               */
  27. /*        C:\WINNT\help\nvcpl.hlp                                                      */
  28. /*        C:\WINNT\help\nvwcplen.hlp                                                   */
  29. /*        C:\WINNT\nview\generic.tvp                                                   */
  30. /* 1 matching device(s) found.                                                         */
  31. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  32.  
  33. "@ECHO OFF"
  34. Trace Off
  35.  
  36. /* Check OS type (should be 32 bits Windows)*/
  37. Parse Upper Source os .
  38. If os <> "WIN32" Then Call Syntax
  39.  
  40. /* Check command line arguments */
  41. Parse Arg test
  42. If test <> "" Then Call Syntax
  43.  
  44. /* Initialize RexxUtil library */
  45. If RxFuncQuery( "sysloadfuncs" ) <> 0 Then Do
  46. 	initRc = RxFuncAdd( "sysloadfuncs", "RexxUtil", "sysloadfuncs" )
  47. 	If initRc = 0 Then Do
  48. 		Call sysloadfuncs
  49. 	End
  50. 	Else Do
  51. 		Say
  52. 		Say "Error "||initRc||" while trying to initialize RegUtil (RexxUtil)"
  53. 		Say
  54. 		Say "This script requires Patrick TJ McPhee's RegUtil library,"
  55. 		Say "available at http://www.interlog.com/~ptjm/"
  56. 		Say
  57. 		Say "Do yo want to download it now? [y/N]"
  58. 		Say
  59. 		download = Translate( SysGetKey( "NOECHO" ) )
  60. 		If download = "Y" Then Do
  61. 			Address SYSTEM "http://www.interlog.com/~ptjm/"
  62. 			Say "Install the downloaded library file and try again."
  63. 		End
  64. 		Else Do
  65. 			Say "Download and install the library and try again."
  66. 		End
  67. 		Exit 1
  68. 	End
  69. End
  70.  
  71. /* Check DEVCON's availability */
  72. Address SYSTEM "DEVCON.EXE /? >NUL 2>&1"
  73. If rc <> 0 Then Do
  74. 	Say
  75. 	Say "This script requires Microsoft's DEVCON.EXE, available at"
  76. 	Say "http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q311272"
  77. 	Say
  78. 	Say "Do yo want to download it now? [y/N]"
  79. 	Say
  80. 	download = Translate( SysGetKey( "NOECHO" ) )
  81. 	If download = "Y" Then Do
  82. 		Address SYSTEM "http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q311272"
  83. 		Say "Install the downloaded file and try again."
  84. 	End
  85. 	Else Do
  86. 		Say "Download the tool and try again."
  87. 	End
  88. 	Exit 1
  89. End
  90.  
  91. /* Use DEVCON to retrieve info, and store it in an array */
  92. Address SYSTEM 'DEVCON.EXE DriverFiles =Display 2>NUL | RXQUEUE'
  93. empty = 0
  94. Do i = 1 By 1 Until Queued( ) = 0
  95. 	Parse Pull line.i
  96. 	line.i = Strip( line.i, "B", " " )
  97. 	If line.i = "" Then Do
  98. 		empty = empty + 1
  99. 		if empty > 5 Then Leave
  100. 	End
  101. 	line.0 = i
  102. End
  103.  
  104. /* Interpret DEVCON's output line by line */
  105. nextLine  = "ID"
  106. fileCount = 0
  107. driver.   = ""
  108. driver.0  = 0
  109. j = 0
  110. Do i = 1 By 1 To line.0
  111. 	Select
  112. 		When Pos( "matching device(s) found.", line.i ) > 0 Then Leave i       /* Last line of output   */
  113. 		When nextLine = "ID" Then Do                                           /* First line for driver */
  114. 			Parse Value line.i With root"\"str1"&"str2"\"str3
  115. 			If str3 <> "" Then Do
  116. 				j = j + 1
  117. 				driver.0 = j
  118. 				driver.j.0 = 0
  119. 				nextLine = "Name"
  120. 			End
  121. 		End
  122. 		When nextLine = "Name" Then Do                                         /* Line with device name */
  123. 			Parse Value line.i With "Name: "name
  124. 			If name <> "" Then Do
  125. 				name = EscName( name )
  126. 				driver.j = name
  127. 				k = 0
  128. 				nextLine = "inf"
  129. 			End
  130. 		End
  131. 		When nextLine = "inf" Then Do                                          /* Line with inf file name */
  132. 			Parse Value line.i With "Driver installed from "inf" ["key"]. "numFiles" file(s) used by driver:"
  133. 			If numFiles <> "" Then Do
  134. 				k = k + 1
  135. 				driver.j.k = inf
  136. 				driver.j.0 = k
  137. 				nextLine = "files"
  138. 			End
  139. 		End
  140. 		When nextLine = "files" Then Do                                        /* Actual driver files */
  141. 			Parse Value line.i With file
  142. 			If file <> "" Then Do
  143. 				k = k + 1
  144. 				If k = numFiles + 1 Then Do
  145. 					nextLine = "ID"
  146. 				End
  147. 				driver.j.k = file
  148. 				driver.j.0 = k
  149. 			End
  150. 		End
  151. 		Otherwise Nop
  152. 	End
  153. End
  154.  
  155. /* Create a target "root" directory */
  156. If SysMkDir( "Video" ) <> 0 Then Do
  157. 	Call SysFileTree "Video", "exist.", "D"
  158. 	If exist.0 <> 1 Then Do
  159. 		Say "Error creating directory Video"
  160. 		Exit 1
  161. 	End
  162. End
  163. Do i = 1 By 1 To driver.0
  164. 	Say "Backing up drivers for display adapter "||driver.i
  165. 	/* Create a subdirectory with the device name */
  166. 	If SysMkDir( "Video\"||driver.i ) <> 0 Then Do
  167. 		Call SysFileTree "Video\"||driver.i, "exist.", "D"
  168. 		If exist.0 <> 1 Then Do
  169. 			Say "Error creating directory Video\"||driver.i
  170. 			Exit 1
  171. 		End
  172. 	End
  173. 	Do j = 1 To driver.i.0
  174. 		driverFile = driver.i.j
  175. 		Do Until driverFile = ""
  176. 			Parse Value driverFile With dummy"\"driverFile
  177. 		End
  178. 		driverFile = dummy
  179. 		copyRc = SysCopyObject( driver.i.j, "Video\"||driver.i||"\"||driverFile )
  180. 		If copyRc <> 0 Then Do
  181. 			Say "Error "||copyRc||" while copying "||driver.i.j
  182. 			Exit 1
  183. 		End
  184. 	End
  185. End
  186.  
  187. Say "Your display adapter drivers are now stored in the directory Video"
  188.  
  189. /* Done */
  190. Exit 0
  191.  
  192.  
  193. EscName: procedure
  194. 	name = Arg( 1 )
  195. 	name = Translate( name, "",  "|" )
  196. 	name = Translate( name, "",  "?" )
  197. 	name = Translate( name, "",  ":" )
  198. 	name = Translate( name, "",  ";" )
  199. 	name = Translate( name, "", "," )
  200. 	name = Translate( name, "",  "/" )
  201. 	name = Translate( name, "",  "\" )
  202. 	name = Translate( name, "[", "(" )
  203. 	name = Translate( name, "]", ")" )
  204. 	name = Translate( name, "and", "&" )
  205. Return name
  206.  
  207.  
  208. Syntax:
  209. 	Say
  210. 	Say "BkVidDrv,  Version 1.00 for Windows 2000 / XP"
  211. 	Say "Backup driver files for every display adapter installed"
  212. 	Say
  213. 	Say "Usage:  BKVIDDRV.REX"
  214. 	Say
  215. 	Say "Note:   This script requires Microsoft's DEVCON.EXE, available at"
  216. 	Say "        http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q311272"
  217. 	Say "        This script also requires Patrick TJ McPhee's RegUtil,"
  218. 	Say "        available at http://www.interlog.com/~ptjm/"
  219. 	Say "        You will be prompted for download if either isn't found."
  220. 	Say
  221. 	Say "Written by Rob van der Woude"
  222. 	Say "http://www.robvanderwoude.com"
  223. 	Exit 1
  224. Return
  225.  

page last uploaded: 2017-04-06, 13:33