setup/devcon/README.md
DevCon is a command-line tool that displays detailed information about devices, and lets you search for and manipulate devices from the command line. DevCon enables, disables, installs, configures, and removes devices on the local computer and displays detailed information about devices on local and remote computers. DevCon is included in the WDK.
This document explains the DevCon design, and how to use the SetupAPI and device installation functions to enumerate devices and perform device operations in a console application. For a complete description of DevCon features and instructions for using them, see the DevCon help file included with the WDK documentation in Driver Development Tools/Tools for Testing Drivers/DevCon.
DevCon is provided in ready-to-run form in tools\devcon. For usage, refer to the document provided with devcon.exe. DevCon is a command line utility with built-in documentation available by typing "devcon help".
You can build the sample in two ways: using the Visual Studio Integrated Development Environment (IDE) or from the command line using the Visual Studio Command Prompt window and the Microsoft Build Engine (MSBuild.exe).
Open Visual Studio. From the File menu, select Open Project/Solution. Navigate to the DevCon sample folder and open the devcon.sln project file.
Right-click the solution in the Solution Explorer and select Configuration Manager.
From the Configuration Manager, select the Active Solution Configuration (for example, Debug or Release) and the Active Solution Platform (for example, Win32) that correspond to the type of build you are interested in.
From the Build menu, click Build Solution (Ctrl+Shift+B).
Previous versions of the WDK used the Windows Build utility (Build.exe) and provided separate build environment windows for each of the supported build configurations. You can use the Visual Studio Command Prompt window for all build configurations.
Open a Visual Studio Command Prompt window. Click Start and search for Developer Command Prompt. If your project is under %PROGRAMFILES%, you need to open the command prompt window using elevated permissions (Run as administrator). From this window you can use MsBuild.exe to build any Visual Studio project by specifying the project (.VcxProj) or solutions (.Sln) file.
Navigate to the project directory and enter the MSbuild command for your target. For example, to perform a clean build of a Visual Studio driver project called devcon.vcxproj, navigate to the project directory and enter the following MSBuild command: msbuild /t:clean /t:build .\devcon.vcxproj.
If the build succeeds, you will find the tools (devcon.exe) in the binary output directory corresponding to the target platform, for example samples\setup\devcon\Debug.
Type devcon find * to list device instances of all present devices on the local machine.
Type devcon status @root\rdp\_mou\0000 to list status of the terminal server mouse driver.
Type devcon status *PNP05* to list status of all COM ports.
Running devcon help will provide a list of commands along with short descriptions of what each command does. devcon help <command> will give more detailed help on that command. The interpretation of each command is done via a dispatch table "DispatchTable" that is at the bottom of "cmds.cpp". Some of the commands make use of a generic device enumerator "EnumerateDevices". A few of these commands will work when given a remote target computer, and will also work if using the 32-bit devcon on Wow64.
A description of some of the more interesting functions and the APIs they use follows:
cmdClasses
cmdListClass
cmdFind cmdFindAll cmdStatus
cmdEnable cmdDisable cmdRestart
cmdUpdate
cmdInstall
cmdRemove
cmdRescan
cmdDPAdd
cmdDPDelete
cmdDPEnum
Reboot
EnumerateDevices
GetHwIds
GetDeviceDescription
DumpDeviceWithInfo
DumpDeviceStatus
DumpDeviceResources
DumpDeviceDriverFiles
DumpDeviceDriverNodes
DumpDeviceStack