Install Hardware from the Command Line

Posted on 2004-11-15
Last Modified: 2012-05-05

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?

Question by:cparker15

    Author Comment

    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.
    LVL 9

    Expert Comment

    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

    Author Comment

    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.
    LVL 2

    Expert Comment

    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.
    LVL 9

    Expert Comment

    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"






    Author Comment

    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.)

    Author Comment

    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.

    Author Comment

    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.
    LVL 7

    Accepted Solution

    Here is some proper commandline stuff...  query, update, install;EN-US;Q311272

    Should be exactly what you need.

    Author Comment

    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.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Migration of Exchange mailbox can be done with the ExProfre.exe tool. But at times, when the ExProfre.exe tool migrates the Exchange Server user profile, it results in numerous synchronization problems. Synchronization error messages appear in the e…
    Ok I have been working on this for some time having learned and gained certification in XenDesktop 4 along came version 5 which was released last month. Since then I have been working to deploy XenDesktop 5 in a small environment with only 2 virt…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now