Question

I am trying to write a VBS script that install an USB/Ethernet adapter on Windows 7.

I've got a .INF file for this device.

I first tried:

Dim WshShell, res
Set WshShell = WScript.CreateObject("WScript.Shell")
res = WshShell.Run(WshShell.ExpandEnvironmentStrings( "%SystemRoot%" ) & "\System32\InfDefaultInstall.exe "" C:\Users\Me\Driver.inf """, 1, True)

res equaled 2.

Then I searched another way to do that and I found:

Dim WshShell, res
Set WshShell = WScript.CreateObject("WScript.Shell")
res = WshShell.Run(WshShell.ExpandEnvironmentStrings( "%SystemRoot%" ) & "\System32\rundll32.exe SETUPAPI.DLL,InstallHinfSection DefaultInstall 132 ""Driver.inf""", 1, True)

res equals 0 but I've got an error popup Installation failed.

What's wrong with my code? For the record, the script is launched with administration rights.

EDIT

I've tried to execute the first command directly in prompt and got: The inf file you selected does not support this method of installation..

Nothing happens with second command in prompt.

This is very weird because I can install the driver "manually" when I launch the device manager and select the inf file (with a warning: Windows can't verify the publisher of this driver software.):

Windows security: Windows can

Once the driver is installed, the class installer property shows NetCfgx.dll,NetClassInstaller. Could it be used?

I also tried with devcon with no success (program returns devcon.exe failed).

Was it helpful?

Solution

How about this way:

1)If you're using "Windows 7", why not take advantage of the driver pre-staging utility that is built right into the OS? W7 ships with a driver utility called "PNPUTIL". Issuing a command as such will add the drivers:

PNPUTIL -a "X:\Path to Driver File\Driver.inf"

This will process the INF and copy the CAT/SYS/INF (and any DLL, EXE, etc) into the "DriverStore" folder... which is the same place Windows stores all the in-built drivers ready for auto plug-and-play instalaltion.

2)If that's not an option for you, look for "DPInst.exe" (or "DPInst64.exe" for 64-bit systems). These are available as part of the Windows PDK (available free from Microsoft) and will process all INFs in the location you put the file and attempt to pre-stage them. This method tries to copy files to the "Drivers", "CatRoot", and "INF" locations which are not as reliable... and it can occassionally fail to copy required DLLs to "System32" folders etc... but 99% of the time (for simple drivers) it just works. I can arrange to send them to you if you can't find them.

Since I found the option (1) above, that has been my best friend. I use option 2 to isntall Canon USB printers and scanners on our base images, etc... so I know that works too.

OTHER TIPS

I had same problem and solved it by explicitly using ASCII version of InstallHinfSection entry point:

res = WshShell.Run("%Comspec% /C %SystemRoot%\System32\rundll32.exe SETUPAPI.DLL,InstallHinfSectionA DefaultInstall 132 ""Driver.inf""", 1, True)

There is probably a better solution, though (like hinting at the script engine which unicode/ASCII flavor to use).

Also I'm using EN-US system so this workaround may fail on more exotic locales.

Try this:

res = WshShell.Run("%Comspec% /C %SystemRoot%\System32\rundll32.exe SETUPAPI.DLL,InstallHinfSection DefaultInstall 132 ""Driver.inf""", 1, True)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top