MAKEMSI quickly and reliably creates MSI files in a non-programmatic way
Have your say! Join the MAKEMSI discussion list or view archive! Suggest improvements. No question too simple or too complex.
[Bottom][Contents][Prev]: Dependency Walker[Next]: DTREG.EXE
Have your say! Join the MAKEMSI discussion list or view archive! Suggest improvements. No question too simple or too complex.
\->Tips and Tricks->Tools->DEVCON.EXE

DEVCON.EXE

This is a Microsoft tool described in Knowledge base article "311272". It is available on Windows 2000+. You may also be interested in the Device Driver Installation section of this manual (it lists other possible tools as well).

The DevCon utility is a command line utility that acts as an alternative to Device Manager. Using DevCon, you can enable, disable, restart, update, remove, and query individual devices or groups of devices. DevCon provides information that is relevant to the developer and is not available in Device Manager.

DevCon is not redistributable (this reduces a nice and useful tool to something with perhaps "some" use). I'm going to assume internal use in your company is not distribution. It is provided for use as a debugging and development tool. You can freely modify DevCon for private use. The sample demonstrates how to use the SetupAPI and CfgMgr32 functions together effectively to enumerate devices and perform device operations. Note that the source is available so you could create your own program based on this.

Example #1 - Install

Note the use of the "^" character to "escape" the ampersand characters in the hardware ID:

devcon install etzkp.inf USB\VID_108C^&PID_0200^&MI_01
devcon install etzkq.inf USB\VID_108C^&PID_0101

Example #2 - Correct Unknown Devices

The following demonstrates the removal of "unknown" devices ("?" in device manager) and if any were found then a hardware scan is performed:

echo off
setlocal
set RemoveFile=Remove.txt
del "%RemoveFile%" >nul 2>&1

@REM *** Remove unknown devices, if any found need a rescan ***
devcon.exe /remove =Unknown > "%RemoveFile%"
type "%RemoveFile%"
find.exe /I "No devices removed" "%RemoveFile%" >nul 2>&1
if errorlevel 1 devcon.exe /rescan

DEVCON.EXE /?

Device Console Help:

DEVCON.EXE [-r] [-m:\\<machine>] <command> [<arg>...]

-r if specified will reboot machine after command is complete, if needed.

<machine> is name of target machine.

<command> is command to perform (see below).

<arg>... is one or more arguments if required by command.

For help on a specific command, type: DEVCON.EXE help <command>
classfilter          Allows modification of class filters.
classes              List all device setup classes.
disable              Disable devices that match the specific hardware or instance ID.
driverfiles          List driver files installed for devices.
drivernodes          Lists all the driver nodes of devices.
enable               Enable devices that match the specific hardware or instance ID.
find                 Find devices that match the specific hardware or instance ID.
findall              Find devices including those that are not present.
help                 Display this information.
hwids                Lists hardware ID's of devices.
install              Manually install a device.
listclass            List all devices for a setup class.
reboot               Reboot local machine.
remove               Remove devices that match the specific hardware or instance ID.
rescan               Scan for new hardware.
resources            Lists hardware resources of devices.
restart              Restart devices that match the specific hardware or instance ID.
sethwid              Modify Hardware ID's of listed root-enumerated devices.
stack                Lists expected driver stack of devices.
status               List running status of devices.
update               Manually update a device.
updateni             Manually update a device (non interactive).

DEVCON.EXE help classfilter

DEVCON.EXE classfilter <class> upper <subcmds> - Upper filters.

DEVCON.EXE classfilter <class> lower <subcmds> - Lower filters.

Modifies upper and lower filters for a device setup class. Changes do not take effect until the effected devices are restarted or the machine is rebooted.



Where <subcmds> iterate the list of services, modifying the services in the filter. In the context of this command, each sub-command works on services in the list relative to previous sub-commands. Examples below.

=     - move back to start of list of services (no "current" service). This is

        assumed prior to the first sub-command.

@svc  - move forward to specified service and treat it as "current" for the next

        sub-command.

!svc  - delete instance of specified service that's after "current" service.

        The place where the deleted service was is now considered the "current"

        service, making '-' and '+' behave exactly the same.

-svc  - insert service before current service (or beginning if none). Inserted

        service becomes new current service.

+svc  - insert service after current service (or end if none). Inserted service

        becomes new current service.



Examples:

If upperfilters of setup class "foo" is A,B,C,B,D,B,E:

DEVCON.EXE classfilter foo upper @D !B  - delete the 3rd 'B'.

DEVCON.EXE classfilter foo upper !B !B !B - delete all 3 instances of 'B'.

DEVCON.EXE classfilter foo upper =!B =!A  - delete first 'B' and first 'A'.

DEVCON.EXE classfilter foo upper !C +CC   - replaces 'C' with 'CC'.

DEVCON.EXE classfilter foo upper @D -CC   - inserts 'CC' before 'D'.

DEVCON.EXE classfilter foo upper @D +CC   - inserts 'CC' after 'D'.

DEVCON.EXE classfilter foo upper -CC      - inserts 'CC' before 'A'.

DEVCON.EXE classfilter foo upper +CC      - inserts 'CC' after 'E'.

DEVCON.EXE classfilter foo upper @D +X +Y - inserts 'X' after 'D' and 'Y' after 'X'.

DEVCON.EXE classfilter foo upper @D -X -Y - inserts 'X' before 'D' and 'Y' before 'X'.

DEVCON.EXE classfilter foo upper @D -X +Y - inserts 'X' before 'D' and 'Y' between 'X' and 'D'.

DEVCON.EXE help classes

DEVCON.EXE [-m:\\<machine>] classes

List all device setup classes.

This command will work for a remote machine.

Classes are listed as <name>: <descr>

where <name> is the class name and <descr> is the class description.

DEVCON.EXE help disable

DEVCON.EXE [-r] disable <id> [<id>...]

DEVCON.EXE [-r] disable =<class> [<id>...]

Disable devices that match the specific hardware or instance ID.

This command will only work for local machine.

Specify -r to reboot automatically if needed.

Examples of <id> are:

*                  - All devices (not recommended)

ISAPNP\PNP0501     - Hardware ID

*PNP*              - Hardware ID with wildcards (* matches anything)

@ISAPNP\*\*        - Instance ID with wildcards (@ prefixes instance ID)

<class> is a setup class name as obtained from the classes command.

Devices are disabled if possible.

DEVCON.EXE help driverfiles

DEVCON.EXE driverfiles <id> [<id>...]

DEVCON.EXE driverfiles =<class> [<id>...]

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

This command will only work for local machine.

Examples of <id> are:

*                  - All devices

ISAPNP\PNP0501     - Hardware ID

*PNP*              - Hardware ID with wildcards (* matches anything)

@ISAPNP\*\*        - Instance ID with wildcards (@ prefixes instance ID)

<class> is a setup class name as obtained from the classes command.

DEVCON.EXE help drivernodes

DEVCON.EXE drivernodes <id> [<id>...]

DEVCON.EXE drivernodes =<class> [<id>...]

Lists driver nodes for devices that match the specific hardware or instance ID.

This command will only work for local machine.

Examples of <id> are:

*                  - All devices

ISAPNP\PNP0501     - Hardware ID

*PNP*              - Hardware ID with wildcards (* matches anything)

@ISAPNP\*\*        - Instance ID with wildcards (@ prefixes instance ID)

<class> is a setup class name as obtained from the classes command.

DEVCON.EXE help enable

DEVCON.EXE [-r] enable <id> [<id>...]

DEVCON.EXE [-r] enable =<class> [<id>...]

Enable devices that match the specific hardware or instance ID.

This command will only work for local machine.

Specify -r to reboot automatically if needed.

Examples of <id> are:

*                  - All devices (not recommended)

ISAPNP\PNP0501     - Hardware ID

*PNP*              - Hardware ID with wildcards (* matches anything)

@ISAPNP\*\*        - Instance ID with wildcards (@ prefixes instance ID)

<class> is a setup class name as obtained from the classes command.

Devices are enabled if possible.

DEVCON.EXE help find

DEVCON.EXE [-m:\\<machine>] find <id> [<id>...]

DEVCON.EXE [-m:\\<machine>] find =<class> [<id>...]

Find devices that match the specific hardware or instance ID.

This command will work for a remote machine.

Examples of <id> are:

*                  - All devices

ISAPNP\PNP0501     - Hardware ID

*PNP*              - Hardware ID with wildcards (* matches anything)

@ISAPNP\*\*        - Instance ID with wildcards (@ prefixes instance ID)

<class> is a setup class name as obtained from the classes command.

Devices are listed as <instance>: <descr>

where <instance> is the unique instance of the device and <descr> is the description.

DEVCON.EXE help findall

DEVCON.EXE [-m:\\<machine>] findall <id> [<id>...]

DEVCON.EXE [-m:\\<machine>] findall =<class> [<id>...]

Find devices that match the specific hardware or instance ID, including those that are not present.

This command will work for a remote machine.

Examples of <id> are:

*                  - All devices

ISAPNP\PNP0501     - Hardware ID

*PNP*              - Hardware ID with wildcards (* matches anything)

@ISAPNP\*\*        - Instance ID with wildcards (@ prefixes instance ID)

<class> is a setup class name as obtained from the classes command.

Devices are listed as <instance>: <descr>

where <instance> is the unique instance of the device and <descr> is the description.

DEVCON.EXE help hwids

DEVCON.EXE [-m:\\<machine>] hwids <id> [<id>...]

DEVCON.EXE [-m:\\<machine>] hwids =<class> [<id>...]

Lists all hardware ID's of devices that match the specific hardware or instance ID.

This command will work for a remote machine.

Examples of <id> are:

*                  - All devices

ISAPNP\PNP0501     - Hardware ID

*PNP*              - Hardware ID with wildcards (* matches anything)

@ISAPNP\*\*        - Instance ID with wildcards (@ prefixes instance ID)

<class> is a setup class name as obtained from the classes command.

DEVCON.EXE help install

DEVCON.EXE [-r] install <inf> <hwid>

Manually installs a device.

This command will only work for local machine.

Specify -r to reboot automatically if needed.

<inf> is an INF to use to install the device.

<hwid> is a hardware ID to apply to the device.

DEVCON.EXE help listclass

DEVCON.EXE [-m:\\<machine>] listclass <class> [<class>...]

List all devices for specific setup classes.

This command will work for a remote machine.

<class> is the class name as obtained from the classes command.

Devices are listed as <instance>: <descr>

where <instance> is the unique instance of the device and <descr> is the description.

DEVCON.EXE help reboot

DEVCON.EXE reboot

Reboot local machine indicating planned hardware install.

DEVCON.EXE help remove

DEVCON.EXE [-r] remove <id> [<id>...]

DEVCON.EXE [-r] remove =<class> [<id>...]

Remove devices that match the specific hardware or instance ID.

This command will only work for local machine.

Specify -r to reboot automatically if needed.

Examples of <id> are:

*                  - All devices (not recommended)

ISAPNP\PNP0501     - Hardware ID

*PNP*              - Hardware ID with wildcards (* matches anything)

@ISAPNP\*\*        - Instance ID with wildcards (@ prefixes instance ID)

<class> is a setup class name as obtained from the classes command.

DEVCON.EXE help rescan

DEVCON.EXE [-m:\\<machine>]

Tell plug&play to scan for new hardware.

DEVCON.EXE help resources

DEVCON.EXE [-m:\\<machine>] resources <id> [<id>...]

DEVCON.EXE [-m:\\<machine>] resources =<class> [<id>...]

Lists hardware resources of devices that match the specific hardware or instance ID.

This command will work for a remote machine.

Examples of <id> are:

*                  - All devices

ISAPNP\PNP0501     - Hardware ID

*PNP*              - Hardware ID with wildcards (* matches anything)

@ISAPNP\*\*        - Instance ID with wildcards (@ prefixes instance ID)

<class> is a setup class name as obtained from the classes command.

DEVCON.EXE help restart

DEVCON.EXE [-r] restart <id> [<id>...]

DEVCON.EXE [-r] restart =<class> [<id>...]

Restarts devices that match the specific hardware or instance ID.

This command will only work for local machine.

Specify -r to reboot automatically if needed.

Examples of <id> are:

*                  - All devices (not recommended)

ISAPNP\PNP0501     - Hardware ID

*PNP*              - Hardware ID with wildcards (* matches anything)

@ISAPNP\*\*        - Instance ID with wildcards (@ prefixes instance ID)

<class> is a setup class name as obtained from the classes command.

Devices are restarted if possible.

DEVCON.EXE help sethwid

DEVCON.EXE [-m:\\<machine>] sethwid <id> [<id>...] := <subcmds>

DEVCON.EXE [-m:\\<machine>] sethwid =<class> [<id>...] := <subcmds>

Modifies the hardware ID's of the listed devices. This command will only work for root-enumerated devices.

This command will work for a remote machine.

Examples of <id> are:

*                  - All devices (not recommended)

ISAPNP\PNP0601     - Hardware ID

*PNP*              - Hardware ID with wildcards (* matches anything)

@ROOT\*\*          - Instance ID with wildcards (@ prefixes instance ID)

<class> is a setup class name as obtained from the classes command.



<subcmds> consists of one or more:

=hwid              - Clear hardware ID list and set it to hwid.

+hwid              - Add or move hardware ID to head of list (better match).

-hwid              - Add or move hardware ID to end of list (worse match).

!hwid              - Remove hardware ID from list.

hwid               - each additional hardware id is inserted after the previous.

DEVCON.EXE help stack

DEVCON.EXE [-m:\\<machine>] stack <id> [<id>...]

DEVCON.EXE [-m:\\<machine>] stack =<class> [<id>...]

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

DEVCON.EXE help status

DEVCON.EXE [-m:\\<machine>] status <id> [<id>...]

DEVCON.EXE [-m:\\<machine>] status =<class> [<id>...]

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

This command will work for a remote machine.

Examples of <id> are:

*                  - All devices

ISAPNP\PNP0501     - Hardware ID

*PNP*              - Hardware ID with wildcards (* matches anything)

@ISAPNP\*\*        - Instance ID with wildcards (@ prefixes instance ID)

<class> is a setup class name as obtained from the classes command.

DEVCON.EXE help update

DEVCON.EXE [-r] update <inf> <hwid>

Update drivers for devices.

This command will only work for local machine.

Specify -r to reboot automatically if needed.

<inf> is an INF to use to install the device.

All devices that match <hwid> are updated.

DEVCON.EXE help updateni

DEVCON.EXE [-r] updateni <inf> <hwid>

Update drivers for devices (Non Interactive).

This command will only work for local machine.

Specify -r to reboot automatically if needed.

<inf> is an INF to use to install the device.

All devices that match <hwid> are updated.

Unsigned installs will fail. No UI will be

presented.


Microsoft awarded me an MVP (Most Valuable Professional award) in 2004, 2005, 2006, 2007, 2008 & 2009 for the Windows SDK (Windows Installer) area.Please email me any feedback, additional information or corrections.
See this page online (look for updates)

[Top][Contents][Prev]: Dependency Walker[Next]: DTREG.EXE


MAKEMSI© is (C)opyright Dennis Bareis 2003-2008 (All rights reserved).
Sunday February 28 2016 at 3:45pm
Visit MAKEMSI's Home Page
Microsoft awarded me an MVP (Most Valuable Professional award) in 2004, 2005, 2006, 2007, 2008 & 2009 for the Windows SDK (Windows Installer) area.