(view source code of bkalldrv.kix as plain text)
; Is help requested?
If $help
Syntax( )
Exit 1
EndIf
; Enable Ctrl+Break
Break On
; Check If inactive drivers should be backuped too
If $all
$finddev = "FindAll"
Else
$finddev = "Find"
EndIf
; Check If DEVCON is available, if not prompt for download
Shell "%COMSPEC% /C DEVCON.EXE /? >NUL 2>&1"
If @Error
? "This batch file requires Microsoft's DEVCON utility."
? "Do you want to download it now? [y/N] "
Get $answer
If $answer = "Y"
Run '%COMSPEC% /C START "" "http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q311272"'
?
? "Install the downloaded files and make sure DEVCON.EXE is in the PATH."
? "Then try again."
EndIf
Exit 1
EndIf
; Initialize variables
$tmpfile = "%Temp%.\" + SubStr( @ScriptName, 1, Len( @ScriptName ) - 4 ) + ".dat"
$tmpfil2 = "%Temp%.\" + SubStr( @ScriptName, 1, Len( @ScriptName ) - 4 ) + ".da2"
$devcount = 0
$filecount = 0
$errors = 0
; Create backup "root" directory
If Exist( "@CurDir\Drivers" ) = 0
MD "@CurDir\Drivers"
EndIf
; Display welcome message
? "Gathering info, please wait..." ?
; Store a list of all devices
Shell '%COMSPEC% /C DEVCON.EXE FindAll * | FIND.EXE "\" > $tmpfile 2>&1'
CLS
; Process the list of devices
If Open( 3, $tmpfile ) = 0
$line = ReadLine( 3 )
While @Error = 0
If InStr( $line, ":" )
$hwid = Trim( SubStr( $line, 1, InStr( $line, ":" ) - 1 ) )
$name = Trim( SubStr( $line, InStr( $line, ":" ) + 1 ) )
$tdir = Esc( $name )
$x = GetDevice( $hwid, $name, $tdir )
EndIf
$line = ReadLine( 3 )
Loop
$x = Close( 3 )
Else
"Error opening $tmpfile" ?
" @SError" ?
Exit 1
EndIf
? "Backuped $filecount files for $devcount devices." ?
If $errors
? "$errors errors were encountered while copying"
? "Check the screen output for error messages..."
EndIf
; Clean up
If Exist( $tmpfile )
DEL $tmpfile
EndIf
If Exist( $tmpfil2 )
DEL $tmpfil2
EndIf
Function GetDevice( $myDevID, $myDevName, $myDevDir )
$class = SubStr( $myDevID, 1, InStr( $myDevID, "\" ) - 1 )
Shell '%COMSPEC% /C DEVCON.EXE DriverFiles "@@$myDevID" > $tmpfil2 2>&1'
If Open( 4, $tmpfil2 ) = 0
$line = ReadLine( 4 )
While @Error = 0
If InStr( $line, ":\" )
"Backing up driver for $myDevName" ?
$devcount = $devcount + 1
; Create "class" directory
If Exist( "@CurDir\Drivers\$class" ) = 0
MD "@CurDir\Drivers\$class"
EndIf
; INF file
If Left( $line, 25 ) = " Driver installed from"
$inf = SubStr( $line, 27, InStr( $line, " [" ) - 27 )
; Create driver directory
If Exist( "@CurDir\Drivers\$class\$myDevDir" ) = 0
MD "@CurDir\Drivers\$class\$myDevDir"
EndIf
; Copy INF file to driver directory
COPY "$inf" "@CurDir\Drivers\$class\$myDevDir" /H
$filecount = $filecount + 1
EndIf
; Driver file
If Left( $line, 8 ) = " "
$file = SubStr( $line, 9 )
If Exist( "@CurDir\Drivers\$class\$myDevDir" ) = 0
MD "@CurDir\Drivers\$class\$myDevDir"
EndIf
; Copy INF file to driver directory
COPY "$file" "@CurDir\Drivers\$class\$myDevDir" /H
$filecount = $filecount + 1
EndIf
EndIf
$line = ReadLine( 4 )
Loop
$x = Close( 4 )
Else
"Error backing up $myDevName" ?
" @SError" ?
$errors = $errors + 1
EndIf
$GetDevice = ""
EndFunction
Function Esc( $myStr )
While InStr( $myStr, "/" )
$myStr = SubStr( $myStr, 1, InStr( $myStr, "/" ) - 1 ) + "_" + SubStr( $myStr, InStr( $myStr, "/" ) + 1 )
Loop
While InStr( $myStr, "," )
$myStr = SubStr( $myStr, 1, InStr( $myStr, "," ) - 1 ) + " " + SubStr( $myStr, InStr( $myStr, "," ) + 1 )
Loop
While InStr( $myStr, ";" )
$myStr = SubStr( $myStr, 1, InStr( $myStr, ";" ) - 1 ) + " " + SubStr( $myStr, InStr( $myStr, ";" ) + 1 )
Loop
While InStr( $myStr, "(" )
$myStr = SubStr( $myStr, 1, InStr( $myStr, "(" ) - 1 ) + "[" + SubStr( $myStr, InStr( $myStr, "(" ) + 1 )
Loop
While InStr( $myStr, ")" )
$myStr = SubStr( $myStr, 1, InStr( $myStr, ")" ) - 1 ) + "]" + SubStr( $myStr, InStr( $myStr, ")" ) + 1 )
Loop
While InStr( $myStr, "&" )
$myStr = SubStr( $myStr, 1, InStr( $myStr, "&" ) - 1 ) + " and " + SubStr( $myStr, InStr( $myStr, "&" ) + 1 )
Loop
While InStr( $myStr, " " )
$myStr = SubStr( $myStr, 1, InStr( $myStr, " " ) - 1 ) + SubStr( $myStr, InStr( $myStr, " " ) + 1 )
Loop
$Esc = $myStr
EndFunction
Function Syntax( )
? "BkAllDrv.kix, Version 1.00"
? "Backup all Windows device drivers, optionally including even inactive ones" ?
? "Usage: KIX32.EXE BKALLDRV.KIX [ $$All=1 ] [ $$Help=1 ]" ?
? "Where: $$All forces backup of drivers for both active and inactive devices"
? " (default is active devices only)"
? " $$Help displays this help screen" ?
? "Notes: [1] This KiXtart script requires Microsoft's DEVCON.EXE, available at"
? " http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q311272"
? " You will be prompted for download if it isn't found."
? " [2] Drivers will be backupped in a directory named Drivers, located"
? " in the current directory."
? " [3] Devices with duplicate names will overwrite each other's files." ?
? "Written by Rob van der Woude"
? "http://www.robvanderwoude.com" ?
EndFunction
page last modified: 2024-04-16; loaded in 0.0083 seconds