OSRLogo
OSRLogoOSRLogoOSRLogo x Subscribe to The NT Insider
OSRLogo
x

Everything Windows Driver Development

x
x
x
GoToHomePage xLoginx
 
 

    Thu, 14 Mar 2019     118020 members

   Login
   Join


 
 
Contents
  Online Dump Analyzer
OSR Dev Blog
The NT Insider
The Basics
File Systems
Downloads
ListServer / Forum
  Express Links
  · The NT Insider Digital Edition - May-June 2016 Now Available!
  · Windows 8.1 Update: VS Express Now Supported
  · HCK Client install on Windows N versions
  · There's a WDFSTRING?
  · When CAN You Call WdfIoQueueP...ously

A GodSend - Inside the DevCon Utility

Have you ever written a driver for Windows XP and cursed the Add/Remove Hardware applet in Control Panel? How about have your boss ask you, “Hey, how about writing us a tool that installs an “.inf” file programmatically?”? If so, you’re missing an opportunity to relieve yourself from a couple of annoying headaches. Consider the DevCon tool, available now as part of the Windows XP DDK (src\setup\devcon). This amazing little utility is powerful, performs some commands remotely, and it is a good example of how to use the SetupDI interface. So in this article, we’ll offer a primer to get your started.

DEVCON Features

The Devcon utility supports the following useful features:

Feature

Description

Classes

Lists all the device setup classes on a machine

Disable

Disables a device or devices that match the input hardware or instance ID

DriverFiles

Lists the driver files installed for devices that match the input hardware or instance ID

DriverNodes

Lists the driver nodes (Fdo/Pdo pairs) for devices that match the input hardware or instance ID

Enable

Enables the devices that match the input hardware or instance ID

Find

Finds the devices that match the input hardware or instance ID

FindAll

Finds the devices that match the input hardware or instance ID, including those that are not present

Hwids

Lists all hardware ID’s of devices that match the input hardware or instance ID

Install

Manually installs a device from an input “.Inf” file and hardware ID

Listclass

Lists all devices for the input setup class or classes

Reboot

Reboots the local machine indicating a planned hardware install

Rescan

Tells the Plug and Play Manager to scan for new hardware

Resources

Lists hardware resources of devices that match the input hardware or instance ID

Restart

Restarts the devices that match the input hardware or instance ID

Stack

Lists the expected driver stack of devices that match the input hardware or instance ID

Status

Lists the running status of devices that match the input hardware or instance ID

Update

Updates drivers for the input “.INF” file and hardware ID

As you can see, Devcon has the abilities of Device Manager and Add/Remove Hardware applet all in one piece of code. I know, I know...it’s only a “Console Mode” application. But, when you’re continually testing your driver’s capabilities by enabling/disabling it (OSR Driver Lab Students will attest to this), waiting for the Device Manager to do it’s scanning and repainting is painfully slow.

One thing to mention before we start is the syntax of the commands: Most commands accept either an <id> or a <class>.

Examples of an <id> are:

  • *- All devices
  • ISAPNP\PNP0501 – Hardware ID
  • *PNP* – Hardware ID with wildcards, * matches anything
  • @ISAPNP\*\* - Instance ID with wildcards, @ prefixes an instance ID

<class> — is a setup class as obtained from the “devcon classes” command

<machine> — refers to a remote machine to reference on commands that allow the –m
                option.

<inf> —  refers to a user specified “.INF” file

So with that, we’ll enumerate Devcon’s features (while providing some “graphical” examples for your benefit).

Class Feature

The Class Feature allows you to list the setup classes that are available on the local or remote machine
(-m:\\machine is used to reference a remote machine). The syntax for this command is “devcon
[-m:\\<machine>] classes” where machine is optionally some remote machine to perform this command on. A typical result from this command is shown in Figure 1.

Figure 1 —  Classes

Disable Feature

The Disable Feature allows the user to disable devices that match the specified hardware or instance id on a local machine. The syntax for this command can be either:

“devcon [-r] disable <id> [<id>...]”, or
“devcon [-r] disable =<class> [<id>...]”

DriverFiles Feature

The DriverFiles command allows the user to list the driver files installed for devices that match the specified hardware or instance Id. The syntax for this command can be either:

“devcon driverfiles <id> [<id>...]”, or
“devcon driverfiles =<class> [<id>...]”

A typical result from the “devcon driverfiles PCI\VEN_1013” command is shown in Figure 2.

Figure 2 —  Driver Files

DriverNodes Feature

The DriverNodes command lists the driver nodes for the devices that match the specified hardware or instance ID. A driver node is Setup’s concept of a driver. This includes all the support for a device such as any services, device-specific co-installers, registry entries and so forth. The services for a device can include a set of PnP drivers (a function driver and any upper and lower filter drivers). The syntax for this command can be either:

“devcon drivernodes <id> [<id>...]”, or
“devcon drivernodes =<class> [<id>...]”

A typical result from the “devcon drivernodes PCI\VEN_1013” command is shown in
Figure 3.

Figure 3 —  DriverNodes - Digitally Signed and All...

Enable Feature

The Enable Feature allows the user to enable devices that match the specified hardware or instance ID. This command will optionally allow the user to perform a reboot automatically (using the –r option) if needed. The syntax for this command can be either:

“devcon [-r] enable <id> [<id>...]”, or
“devcon [-r] enable =<class> [<id>...]”

Find and FindAll Features

The Find and FindAll features allow the user to find devices that match the specified hardware or instance ID. Where the commands differ is that the FindAll command also finds devices that are not present. These commands both work for a remote machine. The syntax for these commands can be either:

“devcon [-m:\\<machine>] find <id> [<id>...]”, or
“devcon [-m:\\<machine>] find =<class> [<id>...]”

Hwids Feature

The Hwids command allows the user to list all the hardware ID’s of devices that match the specified hardware on instance ID on either the local or a remote machine. The syntax for this command can be either:

“devcon [-m:\\<machine>] hwids <id> [<id>...]”, or
“devcon [-m:\\<machine>] hwids =<class> [<id>...]”

Install Feature

The Install feature allows the user to manually install a device by specifying the “.INF” file to use and the hardware ID to apply to that device. The user can optionally specify that an automatic reboot be performed. The syntax of this command is:

“devcon [-r] install <inf> <hwid>”.

An example of the output of the command “devcon install nothing_wdm.inf ROOT\OSRNothing” is shown in Figure 4.

Figure 4 —  Install

ListClass Feature

The ListClass feature allows the user to list all devices for specific setup classes on either the local or remote machine. The classes that can be lists are those classes that were listed as part of the “devcon classes” command. The syntax for this command is:

“devcon [-m:\\<machine>] listclass <class> [<class>…]”.

Reboot Feature

The Reboot feature allows the local machine to reboot and indicates that it is for a planned hardware install. The syntax of this command is:

“devcon reboot”.

Rescan Feature

The Rescan feature tells the PnP Manager on either the local or remote machine to scan for new hardware. The syntax of this command is:

“devcon [-m:\\<machine>]”.

Resources Feature

The Resources Feature allows the user to list hardware resources of a device that matches the specified hardware or instance ID on either the local or remote machine. The syntax for this command is either: 

“devcon [-m:\\<machine>] resources <id> [<id>…]”, or
“devcon [-m:\\<machine>] resources =class [<id>…]”.

The output from the command “devcon resources PCI\VEN_1013” is shown in Figure 5.

Figure 5 —  Resources

Restart Feature

The Restart feature allows the user to restart devices that match the specified hardware or instance Id, with the option of performing a remote automatically if needed. The syntax for this command can be either:

“devcon [-r] restart <id> [<id>…]”, or
“devcon [-r] restart =<class> [<id>…]”.

Stack Feature

The Stack Feature allows the user to list the expected driver stack of devices on the local or remote machine that match the specified hardware or instance ID. The syntax of this command can be either:

“devcon [-m:\\<machine>] stack <id> [<id>…]”, or
“devcon [-m:\\<machine>] stack =<class> [<id>…]”

The output from the command “devcon stack =Volume” is below. Notice that this command lists the upper filters for this class. A typical result of this command is shown in Figure 6.

Figure 6 —  Stack

Status Feature

The Status Feature allows the user to list the running status of the devices that match the specified hardware or instance ID on either the local or remote machine. The syntax for this command can be either:

“devcon [-m:\\<machine>] status <id> [<id>…]”, or
“devcon [-m:\\<machine>] status =<class> [<id>…]”.

Update Feature

The Update feature allows the user to update the drivers for a device also allowing for the user to specify an automatic reboot if needed.  The syntax for this command is:

“devcon [-r] update <inf> <hwid>”.

Summary

The devcon utility is a powerful utility that provides the developer with a powerful command interface to use to interface with the device manager, and it is also a good example of the use of the SetupDI interface for those developers that need to use it.

User Comments
Rate this article and give us feedback. Do you find anything missing? Share your opinion with the community!
Post Your Comment

"Devcon and Driver signing"
I am trying to use Devcon for Driver installation, but since this driver is "not signed", it brings up a pop-up for user to install. If I want to automatically choose yes, how do i do it?

Rating:
07-Mar-06, Rajani Rao


Post Your Comments.
Print this article.
Email this article.
bottom nav links