Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

212 lines
12 KiB

  1. <HTML>
  2. <HEAD>
  3. <TITLE>Text-mode Device Console Sample</TITLE>
  4. <META content="text/html; charset=windows-1252" http-equiv=Content-Type>
  5. <META content="Microsoft FrontPage 5.0" name=GENERATOR>
  6. </HEAD>
  7. <BODY link=#0000ff><FONT face=Verdana size=5>
  8. <H2>DevCon Sample</H2></FONT><FONT face=Verdana size=2>
  9. <P><SPAN style="COLOR: #ff0000; FONT-FAMILY: Arial; FONT-SIZE: 10pt">[This is
  10. preliminary documentation and subject to change.]</SPAN></P>
  11. <H3>SUMMARY</H3>
  12. This document accompanies the &quot;DevCon&quot; sample which is a text-mode
  13. device console. The instructions herein apply to the Windows XP operating
  14. system. DevCon has been designed for use on Windows 2000 and Windows XP. It will
  15. not work on Windows 95, Windows 98 or Windows ME.<p>The &quot;DevCon&quot; sample described in this article is a command line
  16. utility that acts as an alternative to Device Manager. The sample allows one or more
  17. devices to be enabled, disabled, restarted, updated, removed and queried. The
  18. sample demonstrates how to use SetupAPI and CfgMgr32 API's together effectively
  19. to enumerate devices and perform device operations.
  20. <H3>HOW IT WORKS</H3>
  21. <p>Running &quot;devcon help&quot; will provide a list of commands along with
  22. short descriptions of what each command does. &quot;devcon help
  23. &lt;command&gt;&quot; will give more detailed help on that command. The
  24. interpretation of each command is done via a dispatch table &quot;DispatchTable&quot;
  25. that is at the bottom of &quot;cmds.cpp&quot;. Some of the commands make use of
  26. a generic device enumerator &quot;EnumerateDevices&quot;. Some of these commands
  27. will work when given a remote target computer, and will also work if using the
  28. 32-bit devcon on Wow64.&nbsp; A description of some of the more interesting
  29. functions and the APIs they use follows:<h4>cmdClasses</h4>
  30. <p>This command demonstrates the use of SetupDiBuildClassInfoListEx to enumerate
  31. all device class GUID's. The function SetupDiClassNameFromGuidEx and
  32. SetupDiGetClassDescriptionEx are used to obtain more information about each
  33. device class.<h4>cmdListClass</h4>
  34. <p>This command demonstrates the use of SetupDiClassGuidsFromNameEx to enumerate
  35. one or more class GUID's that match the class name. This command also
  36. demonstrates the use of SetupDiGetClassDevsEx to list all the devices for each
  37. class GUID.<h4>cmdFind cmdFindAll cmdStatus</h4>
  38. <p>A simple use of EnumerateDevices (explained below) to list devices and
  39. display different levels of information about each device. Note that all but cmdFindAll use DIGCF_PRESENT to only list information about devices that are
  40. currently present. The main functionality for these and related devices is done
  41. inside FindCallback.<h4>cmdEnable cmdDisable cmdRestart</h4>
  42. <p>These&nbsp;commands show how to issue DIF_PROPERTYCHANGE to enable a device,
  43. disable a device, or restart a device. The main functionality for each of these
  44. commands is done inside ControlCallback.
  45. <p>These operations cannot be done on a remote machine or in the context of
  46. Wow64. CFGMGR32 API's should not be used as they skip class and co-installers.
  47. <h4>cmdUpdate</h4>
  48. <p>This command shows how to use UpdateDriverForPlugAndPlayDevices to update the
  49. driver for all devices to a specific driver. Normally INSTALLFLAG_FORCE would
  50. not be specified allowing UpdateDriverForPlugAndPlayDevices to determine if
  51. there is a better match already known. It's specified in DevCon to allow DevCon
  52. to be used more effectively as a debugging/testing tool. This cannot be done on
  53. a remote machine or in the context of Wow64.
  54. <h4>cmdInstall</h4>
  55. <p>A variation of cmdUpdate to install a driver when there is no associated
  56. hardware. It creates a new root-enumerated device instance and associates it
  57. with a made up hardware ID specified on the command line (which should correspond to a hardware ID
  58. in the INF). This cannot be done on a remote machine or in the context of Wow64.<h4>cmdRemove</h4>
  59. <p>A command to remove devices. Plug &amp; Play devices that are removed will
  60. reappear in response to cmdRescan. The main functionality of this command is in
  61. RemoveCallback that demonstrates the use of DIF_REMOVE. This cannot be done on a
  62. remote machine or in the context of Wow64. CFGMGR32 API's should not be used as
  63. they skip class and co-installers.<h4>cmdRescan</h4>
  64. <p>This command shows the correct way to rescan for all Plug &amp; Play devices
  65. that may have previously been removed, or that otherwise require a rescan to
  66. detect them.
  67. <h4>Reboot</h4>
  68. <p>This function shows how to correctly reboot the machine from a hardware
  69. install program. In particular it passes flags to ExitWindowsEx that cause the
  70. reboot to be associated with hardware installation. You should never reboot the
  71. machine unnecessarily.<h4>EnumerateDevices</h4>
  72. <p>Demonstrates the use of SetupDiGetClassDevsEx to enumerate all devices or all
  73. present devices, either globally or limited to a specific setup class.
  74. Demonstrates the use of SetupDiCreateDeviceInfoListEx to create a blank list
  75. associated with a class or not (for most cases, a blank list need not be
  76. associated with a class). Demonstrates the use of SetupDiOpenDeviceInfo to add a
  77. device instance into a device info list. These last two API's are ideal to
  78. obtain a DeviceInfoData structure from a device instance and machine name when
  79. mixing CFGMGR32 API's with SETUPAPI API's. SetupDiGetDeviceInfoListDetail is
  80. called to obtain a remote machine handle that may be passed into CFGMGR32 API's. SetupDiEnumDeviceInfo
  81. is called to enumerate each and every device that is in the device info list
  82. (either explicitly added, or determined by the call to SetupDiGetClassDevsEx).
  83. The instance ID is obtained by calling CM_Get_Device_ID_Ex, using information in
  84. devInfo (obtained from SetupDiEnumerateDeviceInfo) and devInfoListDetail
  85. (obtained from SetupDiGetDeviceInfoListDetail). GetHwIds is called to obtain
  86. a list of hardware and compatible ID's (explained below). Once an interesting
  87. device has been determined (typically by checking hardware ID's) then the callback is called to operate on that individual device.<h4>GetHwIds</h4>
  88. <p>Shows how to get the complete list of hardware ID's or compatible ID's for a
  89. device using SetupDiGetDeviceRegistryProperty.<h4>GetDeviceDescription</h4>
  90. <p>Shows how to obtain descriptive information about a device. The friendly name
  91. is used if it exists, otherwise the device description is used.<h4>DumpDeviceWithInfo</h4>
  92. <p>Shows how to obtain an instance ID (or use any CFGMGR32 API) given HDEVINFO
  93. (device info list) and PSP_DEVINFO_DATA (device info data).<h4>DumpDeviceStatus</h4>
  94. <p>Shows how to interpret the information returned by CM_Get_DevNode_Status_Ex.
  95. Refer to cfg.h for information returned by this API.
  96. <h4>DumpDeviceResources</h4>
  97. <p>Shows how to obtain information about resources used by a device.<h4>DumpDeviceDriverFiles</h4>
  98. <p>Provided as a debugging aid, obtains information about the files apparently
  99. being used for a device. It uses SetupDiBuildDriverInfoList to obtain
  100. information about the driver being used for the specified device. The driver
  101. list associated with a device may be enumerated by calling SetupDiEnumDriverInfo.
  102. In this case, there will be no more than one driver listed. This function
  103. proceeds to obtain a list of files that would normally be copied for this driver
  104. using DIF_INSTALLDEVICEFILES. SetupScanFileQueue is used to enumerate the file
  105. queue to display the list of files that are associated with the driver.<h4>DumpDeviceDriverNodes</h4>
  106. <p>Provided as a debugging aid, this function determines the list of compatible
  107. drivers for a device. It uses SetupDiBuildDriverInfoList to obtain the list of
  108. compatible drivers. In this case, all drivers are enumerated, however typically
  109. DIF_SELECTBESTCOMPATDRV and SetupDiGetSelectedDriver would be used together to
  110. find which driver the OS would consider to be the best.
  111. <h4>DumpDeviceStack</h4>
  112. <p>This function determines class and device upper and lower filters.
  113. <H3>BUILDING THE DEVCON SAMPLE</H3>
  114. <h5>To build the devcon sample:</h5>
  115. <ol><li>
  116. <p class="MsoListNumber">Click the Build Environment icon of choice in the
  117. Development Kits Build Environments sub-menu. This will set up the correct build
  118. environment to build this sample. Note that this sample will build in the 64-bit
  119. environments as well as the 32-bit environments.
  120. <li>
  121. <p class="MsoListNumber">In a command window, change to the directory containing the DevCon source code. For example:</li>
  122. <blockquote>
  123. <p><b>cd src\setup\devcon</b>
  124. </blockquote>
  125. <li>
  126. <p class="MsoListNumber">Use the macro BLD or run the following from the command prompt:
  127. </ol><blockquote>
  128. <p><b>build �c</b>
  129. <p>This invokes the Microsoft make routines that produce the Build.log, Build.wrn, and Build.err log files.
  130. <p>When the build completes, the executable will be placed in the ObjXXX\I386 subdirectory of the
  131. &lt;TARGETPATH&gt; directory specified in the Sources file (depending on build
  132. environment chosen).
  133. <p>If the build does not succeed, check for these errors: 1) the build environment is not set up
  134. properly, or 2) modifications made to the sample source code introduced errors.
  135. </blockquote>
  136. <H3>USING DEVCON</H3>
  137. <p>DevCon is provided in ready to run form in tools\devcon. For usage, refer to the document
  138. provided with devcon.exe.
  139. DevCon is a command line utility with built in documentation available by typing
  140. &quot;devcon help&quot;.
  141. <H3>TESTING</H3>
  142. <p>Type &quot;devcon find *&quot; to list device instances of all present
  143. devices on the local machine.</p>
  144. <p>Type &quot;devcon status @root\rdp_mou\0000&quot; to list status of the
  145. terminal server mouse driver.</p>
  146. <p>Type &quot;devcon status *PNP05*&quot; to list status of all COM ports.</p>
  147. <H3>CODE TOUR</H3>
  148. <H4>File Manifest</H4>
  149. </FONT><FONT face="Courier" size="3">
  150. <TABLE BORDER=0 CELLSPACING=1 CELLPADDING=0 width="916">
  151. <TR><TD width="151" valign="top"><U>File</u></TD><TD width="755"><u>Description<u></TD></TR>
  152. <TR><TD width="151" valign="top"><i>DevCon.htm</i></TD><TD width="755">Sample tour documentation for this binary (this file).</TD></TR>
  153. <tr>
  154. <TD width="151" valign="top"><i>DevCon.cpp</i></TD><TD width="755">Source file for
  155. tmain entry point and utility functions.</TD>
  156. </tr>
  157. <tr>
  158. <TD width="151" valign="top"><i>Cmds.cpp</i></TD><TD width="755">Source file for
  159. supported commands.</TD>
  160. </tr>
  161. <tr>
  162. <TD width="151" valign="top"><i>Dump.cpp</i></TD><TD width="755">Source file for
  163. functions that output information about devices.</TD>
  164. </tr>
  165. <TR><TD width="151" valign="top"><i>DevCon.h</i></TD><TD width="755">Header file
  166. for sample.</TD></TR>
  167. <TR><TD width="151" valign="top"><i>DevCon.rc</i></TD><TD width="755">Resource file
  168. containing some strings and version information.</TD></TR>
  169. <tr>
  170. <TD width="151" valign="top"><i>rc_ids.h</i></TD><TD width="755">Header file
  171. for resources.</TD>
  172. </tr>
  173. <TR><TD width="151" valign="top"><i>Msg.mc</i></TD><TD width="755">Message file
  174. that is used to build msg.rc and msg.h used for help texts and other
  175. messages.</TD></TR>
  176. <TR><TD width="151" valign="top"><i>Sources</i></TD><TD width="755">Generic file that lists source files and all the build options.</TD></TR>
  177. <TR><TD width="151" valign="top"><i>Makefile</i></TD><TD width="755">File that redirects to the real make file that is shared by all the driver components of the Windows
  178. DDK.</TD></TR>
  179. </TABLE>
  180. <H3>FEEDBACK</H3>
  181. <P>We welcome your comments, problem reports and wish-list requests. Please
  182. submit them by pointing your Internet browser to <A href="http://www.microsoft.com/ddk">http://www.microsoft.com/ddk</A>.
  183. </FONT></P>
  184. <P align=center><FONT face=Verdana size=2><A href="#top">Top of page</A></P></FONT>
  185. <TABLE border=0" cellSpacing="0" width="624">
  186. <TR>
  187. <TD bgColor="#00ffff" height="2" vAlign="middle"></TD></TR></TABLE>
  188. <FONT face="MS Sans Serif" size=1>
  189. <P>&copy; Microsoft Corporation 2001</FONT><FONT face=Verdana size=2>
  190. </P></FONT>
  191. </BODY>