Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am trying to automate the PnP driver installs for Windows 7 with either of the below batch files via For loop and wildcard for the .inf file.

The rundll32 batch reads and echos the correct .inf file but then gives me the "Error Installation failed" and with the pnputil batch it runs without any error put does not install.

How can I correct the batch files to install the inf correctly?

@echo off&color a&setlocal enabledelayedexpansion
cd %~dp0

set PnP=rundll32 syssetup,SetupInfObjectInstallAction DefaultInstall 128 .\*.inf
for /f "delims=" %%a in ('dir/b %PnP%') do (
echo == Installing PnP Drivers == "%%a"
::or
set PnP=pnputil -i -a "*.inf"
for /f "delims=" %%a in ('dir/b %PnP%') do (
echo == Installing PnP Drivers == "%%a"

ping -n 3 localhost 1>nul
start "" /wait %PnP%\%%a
)
cls
echo. * DONE *
pause
exit
share|improve this question

3 Answers 3

After tweaking and testing got this working now – I am posting my code that hopefully may help someone else in the future that needs a fast and convenient way to reinstall all their drivers.

Tested and Working on Windows 7 and Windows 8 with 25+ driver installs in just over 1 minute.

@echo off&color a && Title [ MULTI .INF INSTALLER ]

::= Multi-PnP.Installer.cmd =
:: Put all Pnf, Infs, Cat, Sys files etc.
   together in same directory.

:: Run Batch From Current Directory 
cd %~dp0

:: Scan and Echo .inf files during install
for /f "delims=" %%a in ('dir/b *.inf') do (
echo == Installing PnP Drivers == "%%a"

:: Delay
ping -n 4 localhost 1>nul

:: Windows Plug Play Installer
start "" pnputil -i -a %%a
)
cls
echo. * DONE *
Echo.&Echo.&Echo.
echo == Reboot To Finalize Driver Installs! ==&pause>nul
exit
share|improve this answer
    
I've merged your accounts for now, but in the future please log into Stack Exchange before posting an answer as an unregistered user. Now your accounts are associated and you can accept your own answer in a little less than two days. Cheers! –  slhck Oct 9 '12 at 16:23

The script you made requires the .bat file to be run inside of the folder with all of the driver .inf files, which can be slightly problematic if there are any .dll or .sys files with like names. I slightly modified it so that it'll search deeper so you can catalog multiple drivers from directories inside the same folder as the .bat for a much cleaner and more organized approach!

@echo off&color a && Title [ MULTI .INF INSTALLER ]

::= Multi-PnP.Installer.cmd =
:: Put all Pnf, Infs, Cat, and Sys files etc. in directories inside this one!

:: Run Batch from current directory
cd %~dp0

:: Scan and Echo .inf files duing install
for /f "tokens=* delims=" %%a in ('dir /b /s /o:gen *.inf') do (
echo == Installing PnP Drivers == "%%a"

:: Delay
ping -n 4 localhost 1>nul

:: Windows Plug-n-Play Installer
start "" pnputil -i -a %%a
)
echo * DONE *
Echo.&Echo.&Echo.
echo == Reboot to finalize driver installs! ==&pause>nul
exit

I used this script after extracting Dell's driver .cab files for the models we use at the office to make a universal image that can install windows with the drivers for both models pre loaded into the system, just extract the .cab files somewhere and run this code from where you extracted and it will pull all drivers it finds, the only time it requires human interaction is to warn you about 3rd party drivers.

Thanks by the way! I wouldn't have figured this out unless I found this post! Made my life a lot easier!

share|improve this answer

The above scripts work well if you place the drivers on the machine you intend to update but don't seem to work over a network with the files stored on a server share so I created the below (bases on the other scripts on this page) which does. My Script has some additions to it such as working out how many ini files are in the folder and subfolder(s) and providing a count of the installations plus it displays only the driver ini file name rather then the full path (which could be long and is unneeded). I hope someone finds it useful...

@echo off && Title [ MULTI .INF INSTALLER ]
:: Put all Pnf, Infs, Cat, and Sys files etc. in directories inside this one
:: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
setlocal ENABLEDELAYEDEXPANSION

:: Run Batch from current directory
:: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cd %~dp0

:: Setting variables
:: ~~~~~~~~~~~~~~~~~
set mypath=%~dp0
set Full_list_of_files=%USERPROFILE%\Full_list_of_files.txt
set list_of_INI_files=%USERPROFILE%\list_of_INI_files.txt
set line_count=%USERPROFILE%\line_count.txt
set counter=0
set inf_total=0
set short_name=0
:: Deleting generated files if already exist
:: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if exist %Full_list_of_files% del /f /q %Full_list_of_files%
if exist %list_of_INI_files% del /f /q %list_of_INI_files%
if exist %line_count% del /f /q %line_count%

:: Scan and Echo .inf files during install
:: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cls
echo ----------------------------------------------------------------------------
echo %date% %time% Generating list of INF files. Please Wait ...
dir %mypath% /b /s /-p /o:gen >%Full_list_of_files%
type %Full_list_of_files% | C:\Windows\system32\findstr /i /l ".inf" >%list_of_INI_files%
type %list_of_INI_files% | find /V /C "" >> %line_count%
Set /p inf_total=<%line_count%
del /f /q %line_count%
del /f /q %Full_list_of_files%
echo %date% %time% Starting Driver Installation
echo ----------------------------------------------------------------------------
for /f "tokens=* delims=" %%a in (%list_of_INI_files%) do (set var=%%a) && (set short_name=%%~nxa) && Call :process
goto :ending
:process
set /a counter=%counter%+1
echo Installing Driver %counter% of %inf_total% : "%short_name%"
start pnputil -i -a %var%
ping -n 3 localhost 1>nul
goto :eof
:ending
Echo.&Echo.&Echo.
echo ----------------------------------------------------------------------------
echo.
echo %date% %time% Driver Installation Completed.
echo ----------------------------------------------------------------------------
del /f /q %list_of_INI_files%
echo Please reboot to finalize driver installs &pause>nul
endlocal
exit

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.