Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for bkmdmdrv.rex

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

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

page last uploaded: 2017-08-21, 14:26