Link to home
Start Free TrialLog in
Avatar of cparker15
cparker15

asked on

Install Hardware from the Command Line

Hello,

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?

Thanks!
Avatar of cparker15
cparker15

ASKER

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
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.
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 http://www.svrops.com/svrops/documents/sysprep.htm 
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

;SetupMgrTag
[Unattended]
    OemSkipEula=Yes
    OemPnPDriverPath=Sysprep\Drivers\NETWORK;Sysprep\Drivers\AUDIO;Sysprep\Drivers\
       MODEM;Sysprep\Drivers\VIDEO;Sysprep\Drivers\OTHER     InstallFilesPath=C:\Sysprep\i386

[GuiUnattended]
    AdminPassword=NNNNNNNNNN272d1262b8b53be6a775934870ab041f24e4659b
    EncryptedAdminPassword=Yes
    AutoLogon=Yes
    AutoLogonCount=1
    OEMSkipRegional=1
    OEMDuplicatorstring="Internal Image 2.1.2 (Sysprep.inf 4.1.2) 11-26-2002"
    TimeZone=10

[UserData]
    ProductID=NNNNN-NNNNN-NNNNN-NNNNN-NNNNN
    FullName="Joe User"
    OrgName="My Company, Inc."

[TapiLocation]
    CountryCode=1
    Dialing=Tone
    AreaCode=970
    LongDistanceAccess="9"

[RegionalSettings]
    LanguageGroup=1
    Language=00000409

[GuiRunOnce]
    Command0="\\Server\Share\Install\Setup.exe -q"
    Command1="\\Server\Share\NewUserScript.cmd"

[Identification]
    JoinDomain=DOMAINX
    DomainAdmin=JDAcct
    DomainAdminPassword=JDPass

[Networking]
    InstallDefaultComponents=Yes

[Sysprep]
    BuildMassStorageSection=Yes

[SysprepMassStorage]



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

BATCH:
rundll32.exe shell32.dll,Control_RunDLL hdwwiz.cpl
-OR-
control hdwwiz.cpl
-OR-
hdwwiz.cpl

WINDOWS SCRIPT HOST (VBS):
Option Explicit

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

ShellApplication.ControlPanelItem("hdwwiz.cpl")


I have tested all of these solutions. When I find out more, I will post here.
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:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/install/hh/install/SetupAPI_071eca3a-0cc3-4962-b3de-65dcf056c761.xml.asp

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.
ASKER CERTIFIED SOLUTION
Avatar of tymes
tymes
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.