Archive: Create a script to install a hardware driver


Create a script to install a new hardware driver
HI
As I can create a script to install a new hardware driver in the windows xp and windows 2000

Regards


hi man,

im using ExecWait "rundll32.exe advpack.dll,LaunchINFSection my.inf,DefaultInstall"

to install a inf(driver) for a network connection,

im also using ExecWait "rundll32.exe SysDM.cpl,InstallDevice_RunDLL NetTrans"

to add a protocol, there are many other, for install a printer, for ex.


i think u should look for "rundll32 stuff".

i have no idea on linux :P


here is what I use for all driver installations. You may have to tweak it to account for installing driver applications but it generally works for 9x-2003. This also has a modified version of drvsetup.nsh.

***drivertest.nsi***

!include "winver.nsh"
!include "drvsetup.nsh"

Name "drivertest"
OutFile "drivertest.exe"
SilentInstall silent

Function .onInit
SetOutPath $INSTDIR\Drivers
File /nonfatal /r ".\Drivers\*.*"
!insertmacro InstallUpgradeDriver "$INSTDIR\Drivers" "$INSTDIR\Drivers\DriverInf.inf" "Vendor&DeviceIDInfofromDeviceListSectionofInf"
FunctionEnd

Section
Sectionend

***drvsetup.nsh***

!define sysUpdateDriverForPlugAndPlayDevices "newdev::UpdateDriverForPlugAndPlayDevices(i, t, t, i, *i) i"
!define ERROR_NO_SUCH_DEVINST -536870389

!define sysSetupCopyOEMInf "setupapi::SetupCopyOEMInf(t, t, i, i, i, i, *i, t) i"
!define SPOST_NONE 0
!define SPOST_PATH 1
!define SPOST_URL 2
!define SP_COPY_DELETESOURCE 0x1
!define SP_COPY_REPLACEONLY 0x2
!define SP_COPY_NOOVERWRITE 0x8
!define SP_COPY_OEMINF_CATALOG_ONLY 0x40000

Function InstallUpgradeDriver

Pop $R0 ; HID
Pop $R1 ; INFPATH
Pop $R2 ; INFDIR

Call GetWindowsVersion
Pop $R3 ; Windows Version
;DetailPrint 'Windows Version: $R3'
StrCmp $R3 '2000' lbl_upgrade
StrCmp $R3 'XP' lbl_upgrade
StrCmp $R3 '2003' lbl_upgrade
DetailPrint "Windows $R3 doesn't support automatic driver updates."

; Upgrade the driver if the device is already plugged in
Goto lbl_noupgrade
lbl_upgrade:
System::Get '${sysUpdateDriverForPlugAndPlayDevices}'
Pop $0
StrCmp $0 'error' lbl_noapi
DetailPrint "Updating the driver..."
; 0, HID, INFPATH, 0, 0
Push $INSTDIR ; Otherwise this function will swallow it, dunno why
System::Call '${sysUpdateDriverForPlugAndPlayDevices}?e (0, R0, R1, 0, 0) .r0'
Pop $1 ; last error
Pop $INSTDIR
IntCmp $0 1 lbl_done
IntCmp $1 ${ERROR_NO_SUCH_DEVINST} lbl_notplugged

DetailPrint "Driver update has failed. ($R3:$0,$1)"
Goto lbl_noupgrade
lbl_notplugged:
DetailPrint "The device is not plugged in, cannot update the driver."
Goto lbl_noupgrade
lbl_noapi:
DetailPrint "Your Windows $R3 doesn't support driver updates."

lbl_noupgrade:
; Pre-install the driver
System::Get '${sysSetupCopyOEMInf}'
Pop $0
StrCmp $0 'error' lbl_inoapi
DetailPrint "Installing the driver..."
; INFPATH, INFDIR, SPOST_PATH, "", 0, 0, 0, 0
System::Call '${sysSetupCopyOEMInf}?e (R1, R2, ${SPOST_PATH}, 0, 0, 0, 0, 0) .r0'
Pop $1 ; last error
IntCmp $0 1 lbl_nodriver
DetailPrint 'Driver pre-installation has failed with error #$1 ($R3)'
Goto lbl_done
lbl_inoapi:
DetailPrint "Your Windows $R3 doesn't support driver pre-installation."
lbl_nodriver:
lbl_done:

StrCmp $R3 '95' lbl_forcescan
StrCmp $R3 '98' lbl_forcescan
StrCmp $R3 'ME' lbl_forcescan
StrCmp $R3 '2000' lbl_skipscan
StrCmp $R3 'XP' lbl_skipscan
StrCmp $R3 '2003' lbl_skipscan
lbl_forcescan:
Delete "$WINDIR\INF\drvdata.bin"
Delete "$WINDIR\INF\drvidx.bin"
StrCpy $1 ""
System::Get 'setupapi::CM_Locate_DevNodeA(*i .r0, t r1, i r2) i .r3'
Pop $0
StrCmp $0 'error' lbl_noapi1
System::Call 'setupapi::CM_Locate_DevNodeA(*i .r0, t r1, i r2) i .r3'
System::Call 'setupapi::CM_Reenumerate_DevNode(i r0, i r4) i .r5'
Goto lbl_done1
lbl_noapi1:
ClearErrors
ExecWait "$WINDIR\rundll.exe setupx.dll,dibuilddriverindex"
IfErrors 0 +2
ExecWait "$WINDIR\rundll32.exe setupx.dll,dibuilddriverindex"
lbl_done1:
lbl_skipscan:
SetPluginUnload manual
System::Free 0
FunctionEnd

!macro InstallUpgradeDriver infdir infpath hwid
Push "${infdir}"
Push "${infpath}"
Push "${hwid}"
Call InstallUpgradeDriver
Sleep 1000
!macroend