Install Hardware from the Command Line


I've put together an unattended installation of Windows XP Professional, and it's almost done, except for one thing...

Some of the device drivers I need to install don't have Setup programs to install them. They're just the .sys file and the .inf file.

I've put together a batch script that I thought should install the hardware, but it doesn't seem to do the trick.

So far, I've only been able to install the hardware by opening up the Device Manager, finding the piece of hardware in need of drivers, and clicking Update Driver. Once I do that, I have to point the Add New Hardware wizard to the inf file and then the driver installs successfully.

I need to automate this process without any user input. I've gone and tried everything to no avail, and I'm starting to pull the hair from my head. I'm working on a deadline, so it'd be nice if I could solve the mystery here, regardless of how.

How would I go about doing this?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cparker15Author Commented:
By the way, here's the batch script I referenced:

<blockquote><code>@ECHO OFF

%SystemRoot%\System32\rundll32.exe setupapi,InstallHinfSection DefaultInstall 132 %*\setup.inf</code></blockquote>

The inf file is always named "setup.inf", and it accepts the path to the inf file as input.

An example of how to call this batch script, assuming the inf file were stored at C:\My Documents\My Drivers\Foo\Bar and the batch script were called "addhardware.cmd":

> .\addhardware.cmd C:\My Documents\My Drivers\Foo\Bar

I use the %* variable because it's possible (and expected) for the path to contain spaces, hence the path would be spread out across multiple %1, %2, etc. arguments.
i think when you install drivers with a setup routine you tell windows to lanch the setup.exe file i think you can do the same with a .inf file if you right click the inf file it says install so may be you just use the system prep tool to lanch the inf file as well during setup
cparker15Author Commented:
The batch script source I've included mimicks the actions performed on the "Install" entry of an inf file's context menu.

To see the actions taken with the "Install" entry, double-click "Folder Options" in your Control Panel, then click the File Types tab. Scroll down to where you see the information for INF files, click the entry, then click the Advanced button in the "Details for 'INF' extension" group.

You'll see the different options available for context menus defined there. Click on "Install" then the Edit button to the right. On my Windows 2000 machine, this is the result:

C:\WINNT\System32\rundll32.exe setupapi,InstallHinfSection DefaultInstall 132 %1

So, it seems as though just right-clicking on an INF file and then clicking "Install" is not good enough, and that it alone will not install the hardware associated with the driver, as I've tried doing it that way, too.

Thanks for the effort.
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Why are you wanting to do this, if it to install on more then one machine, I would use ghost, although it isnt free it is a must have for most techs.
this may help 
copyed from the above site

6. Also, since Sysprep enumerates (or rediscovers) hardware the first time the cloned PC boots up, you may need driver files for some hardware if the drivers don't come with your OS installation files. If this is the case, create a drivers directory under c:\sysprep and in the drivers directory create a separate folder for each device that needs drivers installed. For example, if you need to add drivers for your video card and NIC, you could create:
c:\sysprep\drivers\video and c:\sysprep\drivers\nic.

In each of those folders (..\video, ..\nic) copy the needed driver files. These files must contain not only the driver files, but an .inf and a .cat file for the device to be installed. Do not copy a binary file (.exe) that your hardware manufacturer created to update your hardware.

You then must indicate in your sysprep.inf file the location of these files.
(see the example sysprep.inf below)

Listing 1: Sample sysprep.inf file

       MODEM;Sysprep\Drivers\VIDEO;Sysprep\Drivers\OTHER     InstallFilesPath=C:\Sysprep\i386

    OEMDuplicatorstring="Internal Image 2.1.2 (Sysprep.inf 4.1.2) 11-26-2002"

    FullName="Joe User"
    OrgName="My Company, Inc."



    Command0="\\Server\Share\Install\Setup.exe -q"





cparker15Author Commented:
To vladonator:

The script I've written is to prepare a Windows install for ghosting. While it would be acceptable to install hardware manually, there are dozens of different systems that are going to be in use. It would be better if I could mimick the Add New Hardware wizard so it's all seemless. Having this capability would cut out the hours it would take to set up these systems in the long run, and real work could get done instead. The script I've written should be 100% complete. One of the requirements of this script is to install all drivers, which would include Add New Hardware wizard replacement in this respect.

To andymsmith18:

I do already have something very similar to this already in place. However, the sysprep/unattend methods won't work for what I'm trying to do. I need to mimick the Add New Hardware wizard's functionality with my script, so that it is all done without user interaction. The fact that I'm doing an unattended install is transparent to my application.

If anyone knows how I can install hardware drivers from the command line using an INF file and a SYS file (no CAT files), please respond. An acceptable solution may be given either in batch or WSH (e.g.: VBS) formats. I need it to accomplish the same thing that sysdm.cpl does. (If there's a way to hook into sysdm.cpl from the command line, this would also be an acceptable solution.)
cparker15Author Commented:
Well, I've found out how to directly access the Add/Remove Hardware wizard. Now I just need to know if it accepts any command line switches. If not, I think I should be able to force keystrokes onto the applet.

Here's how to call the Add/Remove Hardware wizard:

rundll32.exe shell32.dll,Control_RunDLL hdwwiz.cpl
control hdwwiz.cpl

Option Explicit

Dim ShellApplication: Set ShellApplication = CreateObject("Shell.Application")


I have tested all of these solutions. When I find out more, I will post here.
cparker15Author Commented:
I don't think that hdwwiz.cpl can be passed arguments from the command line.

Instead, I'm going to have to do what hdwwiz.cpl does to install hardware.

Information on how to do this (after much searching) is available at:

Some sections are incomplete. It looks like they're still working on them. As of this posting, they have all been updated in early (02-04) September, 2004.

I'm going to go down this route, and if I come up with something, I'll post my results here.
Here is some proper commandline stuff...  query, update, install;EN-US;Q311272

Should be exactly what you need.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cparker15Author Commented:
Thank you for this answer. Come to think of it, this KB article looks vaguely familiar. I must've glanced at it once before and didn't realize it would eventually prove to be useful.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows XP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.