Source code of Windows XP (NT5)
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.

236 lines
8.1 KiB

  1. #include "precomp.h"
  2. #pragma hdrstop
  3. //
  4. // Format: devprop <Enumerator | DeviceId | *> [-m <MachineName>]
  5. //
  6. TCHAR DevPropTable[][34] = {
  7. TEXT("SPDRP_DEVICEDESC"),
  8. TEXT("SPDRP_HARDWAREID"),
  9. TEXT("SPDRP_COMPATIBLEIDS"),
  10. TEXT("SPDRP_UNUSED0"),
  11. TEXT("SPDRP_SERVICE"),
  12. TEXT("SPDRP_UNUSED1"),
  13. TEXT("SPDRP_UNUSED2"),
  14. TEXT("SPDRP_CLASS"),
  15. TEXT("SPDRP_CLASSGUID"),
  16. TEXT("SPDRP_DRIVER"),
  17. TEXT("SPDRP_CONFIGFLAGS"),
  18. TEXT("SPDRP_MFG"),
  19. TEXT("SPDRP_FRIENDLYNAME"),
  20. TEXT("SPDRP_LOCATION_INFORMATION"),
  21. TEXT("SPDRP_PHYSICAL_DEVICE_OBJECT_NAME"),
  22. TEXT("SPDRP_CAPABILITIES"),
  23. TEXT("SPDRP_UI_NUMBER"),
  24. TEXT("SPDRP_UPPERFILTERS"),
  25. TEXT("SPDRP_LOWERFILTERS"),
  26. TEXT("SPDRP_BUSTYPEGUID"),
  27. TEXT("SPDRP_LEGACYBUSTYPE"),
  28. TEXT("SPDRP_BUSNUMBER"),
  29. TEXT("SPDRP_ENUMERATOR_NAME"),
  30. TEXT("SPDPR_SECURITY"),
  31. TEXT("SPDRP_SECURITY_SDS"),
  32. TEXT("SPDRP_DEVTYPE"),
  33. TEXT("SPDRP_EXCLUSIVE"),
  34. TEXT("SPDRP_CHARACTERISTICS"),
  35. TEXT("SPDRP_ADDRESS"),
  36. TEXT("SPDRP_UI_NUMBER_DESC_FORMAT")
  37. };
  38. int
  39. __cdecl
  40. _tmain(
  41. IN int argc,
  42. IN PTCHAR argv[]
  43. )
  44. {
  45. TCHAR DeviceId[MAX_DEVICE_ID_LEN];
  46. TCHAR MachineName[SP_MAX_MACHINENAME_LENGTH];
  47. int CharsInUnicodeString;
  48. HDEVINFO DeviceInfoSet;
  49. SP_DEVINFO_DATA DeviceInfoData;
  50. DWORD Err;
  51. DWORD i, j, k, RegDataType, BufferSize;
  52. BYTE Buffer[1024];
  53. LPCTSTR CurString;
  54. LPCTSTR MachineNameString = NULL;
  55. BOOL OpenSpecificDevice = FALSE;
  56. if((argc < 2) || !lstrcmp(argv[1], TEXT("-?")) || !lstrcmp(argv[1], TEXT("/?"))) {
  57. _tprintf(TEXT("Usage: devprop <Enumerator | DeviceId | *> [-m <MachineName>]\n"));
  58. return -1;
  59. }
  60. //
  61. // The user specified either an enumerator name, a specific device ID, or a
  62. // wildcard ('*'). We can tell the difference between the first two based
  63. // on whether or not there's a path separator character in the string.
  64. //
  65. if(lstrlen(argv[1]) >= MAX_DEVICE_ID_LEN) {
  66. _tprintf(TEXT("DeviceId must be less than %d characters.\n"), MAX_DEVICE_ID_LEN);
  67. return -1;
  68. }
  69. lstrcpyn(DeviceId, argv[1], MAX_DEVICE_ID_LEN);
  70. if((lstrlen(DeviceId) == 1) && (*DeviceId == TEXT('*'))) {
  71. //
  72. // The wildcard character ('*') was specified--process all devices
  73. //
  74. CurString = NULL;
  75. } else if(_tcschr(DeviceId, TEXT('\\'))) {
  76. //
  77. // This device has a path separator character--assume it's a valid
  78. // device id.
  79. //
  80. OpenSpecificDevice = TRUE;
  81. } else {
  82. //
  83. // Assume this string is an enumerator name.
  84. //
  85. CurString = DeviceId;
  86. }
  87. //
  88. // See if the user pointed us at a remote machine via the "-m" option.
  89. //
  90. if((argc > 3) && !_tcsicmp(argv[2], TEXT("-m"))) {
  91. if(lstrlen(argv[3]) >= SP_MAX_MACHINENAME_LENGTH) {
  92. _tprintf(TEXT("Machine name must be less than %d characters.\n"), SP_MAX_MACHINENAME_LENGTH);
  93. return -1;
  94. }
  95. lstrcpy(MachineName, argv[3]);
  96. MachineNameString = MachineName;
  97. }
  98. if(OpenSpecificDevice) {
  99. //
  100. // Create an HDEVINFO set, and open up a device information element for the specified
  101. // device within that set.
  102. //
  103. DeviceInfoSet = SetupDiCreateDeviceInfoListEx(NULL, NULL, MachineNameString, NULL);
  104. if(DeviceInfoSet == INVALID_HANDLE_VALUE) {
  105. _tprintf(TEXT("SetupDiCreateDeviceInfoList failed with %lx\n"), GetLastError());
  106. return -1;
  107. }
  108. if(!SetupDiOpenDeviceInfo(DeviceInfoSet,
  109. DeviceId,
  110. NULL,
  111. 0,
  112. NULL)) {
  113. Err = GetLastError();
  114. _tprintf(TEXT("SetupDiOpenDeviceInfo failed with %lx\n"), Err);
  115. SetupDiDestroyDeviceInfoList(DeviceInfoSet);
  116. return -1;
  117. }
  118. } else {
  119. DeviceInfoSet = SetupDiGetClassDevsEx(NULL,
  120. CurString,
  121. NULL,
  122. DIGCF_ALLCLASSES,
  123. NULL,
  124. MachineNameString,
  125. NULL
  126. );
  127. if(DeviceInfoSet == INVALID_HANDLE_VALUE) {
  128. _tprintf(TEXT("SetupDiGetClassDevs failed with %lx\n"), GetLastError());
  129. return -1;
  130. }
  131. }
  132. DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
  133. for(i = 0;
  134. SetupDiEnumDeviceInfo(DeviceInfoSet, i, &DeviceInfoData);
  135. i++)
  136. {
  137. SetupDiGetDeviceInstanceId(DeviceInfoSet,
  138. &DeviceInfoData,
  139. DeviceId,
  140. MAX_DEVICE_ID_LEN,
  141. NULL
  142. );
  143. _tprintf(TEXT("For device \"%s\"\n"), DeviceId);
  144. for(j = 0; j < (sizeof(DevPropTable) / sizeof(DevPropTable[0])); j++) {
  145. _tprintf(TEXT(" %s : ("), DevPropTable[j]);
  146. if(SetupDiGetDeviceRegistryProperty(DeviceInfoSet,
  147. &DeviceInfoData,
  148. j,
  149. &RegDataType,
  150. Buffer,
  151. sizeof(Buffer),
  152. &BufferSize)) {
  153. Err = NO_ERROR;
  154. } else {
  155. Err = GetLastError();
  156. }
  157. if(Err == NO_ERROR) {
  158. switch(RegDataType) {
  159. case REG_SZ :
  160. _tprintf(TEXT("REG_SZ:%d) \"%s\"\n"),
  161. BufferSize,
  162. (LPCTSTR)Buffer
  163. );
  164. break;
  165. case REG_MULTI_SZ :
  166. _tprintf(TEXT("REG_MULTI_SZ:%d)"), BufferSize);
  167. for(CurString = (LPCTSTR)Buffer;
  168. *CurString;
  169. CurString += lstrlen(CurString) + 1) {
  170. _tprintf(TEXT(" \"%s\""), CurString);
  171. }
  172. _tprintf(TEXT("\n"));
  173. break;
  174. case REG_DWORD :
  175. _tprintf(TEXT("REG_DWORD:%d) %lx\n"),
  176. BufferSize,
  177. *((PDWORD)Buffer)
  178. );
  179. break;
  180. case REG_BINARY :
  181. _tprintf(TEXT("REG_BINARY:%d)"), BufferSize);
  182. for(k = 0; k < BufferSize; k++) {
  183. _tprintf(TEXT(" %lx"), Buffer[k]);
  184. }
  185. _tprintf(TEXT("\n"));
  186. break;
  187. default :
  188. _tprintf(TEXT("Registry data type %lx:%d)\n"),
  189. RegDataType,
  190. BufferSize
  191. );
  192. }
  193. } else {
  194. _tprintf(TEXT("Error %lx)\n"), Err);
  195. }
  196. }
  197. }
  198. SetupDiDestroyDeviceInfoList(DeviceInfoSet);
  199. return 0;
  200. }