(view source code of bkalldrv.rex as plain text)
/* Backup all Windows drivers with DEVCON *//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//* Sample DEVCON output: *//* *//* PCI\VEN_127A&DEV_1035&SUBSYS_1035127A&REV_08\4&11CD5334&0&48F0 *//* Name: CXT1035 - HCF PCI Modem *//* Driver installed from c:\winnt\inf\oem8.inf [Modem]. 2 file(s) used by driver: *//* C:\WINNT\system32\DRIVERS\winachcf.sys *//* C:\WINNT\system32\cxt1035.cty *//* 1 matching device(s) found. *//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//* Hide command output and error codes */"@ECHO OFF"Trace Off
/* Initialize variables */error = 0
/* Check OS type (should be 32 bits Windows)*/Parse Upper Source os .
If os <> "WIN32" Then Call Syntax
/* Check command line arguments */Parse Arg test
If test <> "" Then Call Syntax
/* Initialize RexxUtil library */If RxFuncQuery( "sysloadfuncs" ) <> 0 Then Do
initRc = RxFuncAdd( "sysloadfuncs", "RexxUtil", "sysloadfuncs" )
If initRc = 0 Then Do
Call sysloadfuncs EndElse Do
SaySay "Error "||initRc||" while trying to initialize RegUtil (RexxUtil)"
SaySay "This script requires Patrick TJ McPhee's RegUtil library,"
Say "available at http://www.interlog.com/~ptjm/"
SaySay "Do yo want to download it now? [y/N]"
Saydownload = Translate( SysGetKey( "NOECHO" ) )
If download = "Y" Then Do
Address SYSTEM "http://www.interlog.com/~ptjm/"
Say "Install the downloaded library file and try again."
EndElse Do
Say "Download and install the library and try again."
EndExit 1
EndEnd/* Check DEVCON's availability */Address SYSTEM "DEVCON.EXE /? >NUL 2>&1"
If rc <> 0 Then Do
SaySay "This script requires Microsoft's DEVCON.EXE, available at"
Say "http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q311272"
SaySay "Do yo want to download it now? [y/N]"
Saydownload = Translate( SysGetKey( "NOECHO" ) )
If download = "Y" Then Do
Address SYSTEM "http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q311272"
Say "Install the downloaded file and try again."
EndElse Do
Say "Download the tool and try again."
EndExit 1
End/* Use DEVCON to retrieve info, and store it in an array */Address SYSTEM 'DEVCON.EXE DriverFiles * 2>NUL | RXQUEUE'
empty = 0
Do i = 1 By 1 Until Queued( ) = 0
Parse Pull line.i
line.i = Strip( line.i, "B", " " )
If line.i = "" Then Do
empty = empty + 1
if empty > 5 Then Leave
End line.0 = iEnd/* Interpret DEVCON's output line by line */nextLine = "ID"
fileCount = 0
driver. = ""
driver.0 = 0
j = 0
Do i = 1 By 1 To line.0
SelectWhen Pos( "matching device(s) found.", line.i ) > 0 Then Leave i /* Last line of output */
When nextLine = "ID" Then Do /* First line for driver */
Parse Value line.i With root"\"str1"&".
If str1 <> "" Then Do
j = j + 1
driver.0 = jdriver.j.0 = 0
driver.j.class = rootnextLine = "Name"
End EndWhen nextLine = "Name" Then Do /* Line with device name */
Parse Value line.i With "Name: "drvname
If drvname <> "" Then Do
k = 0
nextLine = "inf"
driver.j.name = EscName( drvname )
End EndWhen nextLine = "inf" Then Do /* Line with inf file name */
Parse Value line.i With "Driver installed from "inf" ["key"]. "numFiles" file"s" used by driver:"
If numFiles <> "" Then Do
k = k + 1
driver.j.k = inf driver.j.0 = knextLine = "files"
If Translate( numFiles ) = "NO" Then Do
numFiles = 0
nextLine = "ID"
End End EndWhen nextLine = "files" Then Do /* Actual driver files */
Parse Value line.i With file
If file <> "" Then Do
If k = numFiles Then nextLine = "ID"
k = k + 1
driver.j.k = file driver.j.0 = k End EndOtherwise Nop
EndEnd/* Create a target "root" directory */If SysMkDir( "Drivers" ) <> 0 Then Do
Call SysFileTree "Drivers", "exist.", "D"
If exist.0 <> 1 Then Do
Say "Error creating directory Drivers"
SaySay "Aborting..."
Exit 1
EndEnd/* Create "class" directories */Do i = 1 By 1 To driver.0
/* Create a subdirectory with the device class */If SysMkDir( "Drivers\"||driver.i.class ) <> 0 Then Do
Call SysFileTree "Drivers\"||driver.i.class, "exist.", "D"
If exist.0 <> 1 Then Do
Say "Error creating directory Drivers\"||driver.i.class
SaySay "Aborting..."
Exit 1
End EndEnd/* Create individual driver directories */Do i = 1 By 1 To driver.0
/* Create a subdirectory with the device name */If SysMkDir( "Drivers\"||driver.i.class||"\"||driver.i.name ) <> 0 Then Do
Call SysFileTree "Drivers\"||driver.i.class||"\"||driver.i.name, "exist.", "D"
If exist.0 <> 1 Then Do
Say "Error creating directory Drivers\"||driver.i.class||"\"||driver.i.name
SaySay "Aborting..."
Exit 1
End EndEnd/* Copy the driver files based on the values stored in the array */Do i = 1 By 1 To driver.0
Say "Backing up drivers for "||driver.i.name
Do j = 1 To driver.i.0
driverFile = driver.i.jDo Until driverFile = ""
Parse Value driverFile With dummy"\"driverFile
End driverFile = dummycopyRc = SysCopyObject( driver.i.j, "Drivers\"||driver.i.class||"\"||driver.i.name||"\"||driverFile )
If copyRc <> 0 Then Do
Say "Error "||copyRc||" while copying "||driver.i.j
error = 1
End EndEnd/* Summarize copy errors */If error = 1 Then Do
SaySay "Some error(s) occurred while copying files,"
Say "check screen output for error messages..."
End/* A goodbye message */SaySay "Your drivers are now stored in the directory Drivers"
/* Done */Exit error
EscName: procedure
namestr = Arg( 1 )
namestr = Translate( namestr, "", "?" )
namestr = Translate( namestr, "", ":" )
namestr = Translate( namestr, " ", ";" )
namestr = Translate( namestr, " ", "," )
namestr = Translate( namestr, "_", "|" )
namestr = Translate( namestr, "_", "/" )
namestr = Translate( namestr, "_", "\" )
namestr = Translate( namestr, "[", "(" )
namestr = Translate( namestr, "]", ")" )
namestr = Translate( namestr, " and ", "&" )
namestr = Translate( namestr, " ", " " )
Return namestrSyntax:
SaySay "BkAllDrv.rex, Version 1.02 for Windows 2000 / XP"
Say "Backup all Windows device drivers"
SaySay "Usage: BKALLDRV.REX"
SaySay "Note: This script requires Microsoft's DEVCON.EXE, available at"
Say " http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q311272"
Say " Also required is Patrick TJ McPhee's RexxUtil,"
Say " available as RegUtil at http://www.interlog.com/~ptjm/"
Say " You will be prompted for download if either isn't found."
SaySay "Written by Rob van der Woude"
Say "http://www.robvanderwoude.com"
Exit 1
Returnpage last modified: 2025-10-11; loaded in 0.0093 seconds