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.

122 lines
2.5 KiB

  1. // Copyright (c) 1998 - 1999 Microsoft Corporation
  2. /*++
  3. Module Name:
  4. drdetect
  5. Abstract:
  6. Detect whether RDPDR was properly installed.
  7. Environment:
  8. User mode
  9. Author:
  10. Tadb
  11. --*/
  12. #include "stdafx.h"
  13. #include <setupapi.h>
  14. ////////////////////////////////////////////////////////////
  15. //
  16. // Internal Defines
  17. //
  18. #define RDPDRPNPID _T("ROOT\\RDPDR")
  19. #define RDPDRDEVICEID TEXT("Root\\RDPDR\\0000")
  20. const GUID GUID_DEVCLASS_SYSTEM =
  21. { 0x4d36e97dL, 0xe325, 0x11ce, { 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 } };
  22. ULONG RDPDRINST_DetectInstall()
  23. /*++
  24. Routine Description:
  25. Return the number of RDPDR.SYS devices found.
  26. Arguments:
  27. NA
  28. Return Value:
  29. TRUE on success. FALSE, otherwise.
  30. --*/
  31. {
  32. HDEVINFO devInfoSet;
  33. SP_DEVINFO_DATA deviceInfoData;
  34. DWORD iLoop;
  35. BOOL bMoreDevices;
  36. ULONG count;
  37. TCHAR pnpID[256];
  38. GUID *pGuid=(GUID *)&GUID_DEVCLASS_SYSTEM;
  39. //
  40. // Get the set of all devices with the RDPDR PnP ID.
  41. //
  42. devInfoSet = SetupDiGetClassDevs(pGuid, NULL, NULL,
  43. DIGCF_PRESENT);
  44. if (devInfoSet == INVALID_HANDLE_VALUE) {
  45. fprintf(stderr, "Error getting RDPDR devices from PnP. Error code: %ld.",
  46. GetLastError());
  47. return 0;
  48. }
  49. // Get the first device.
  50. iLoop=0;
  51. deviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
  52. bMoreDevices=SetupDiEnumDeviceInfo(devInfoSet, iLoop, &deviceInfoData);
  53. // Get the details for all matching device interfaces.
  54. count = 0;
  55. while (bMoreDevices)
  56. {
  57. // Get the PnP ID for the device.
  58. if (!SetupDiGetDeviceRegistryProperty(devInfoSet, &deviceInfoData,
  59. SPDRP_HARDWAREID, NULL, (BYTE *)pnpID,
  60. sizeof(pnpID), NULL)) {
  61. fprintf(stderr, "Error fetching PnP ID in RDPDR device node remove. Error code: %ld.",
  62. GetLastError());
  63. }
  64. // If the current device matches the RDPDR PNP ID
  65. if (!_tcscmp(pnpID, RDPDRPNPID)) {
  66. count++;
  67. }
  68. // Get the next one device interface.
  69. bMoreDevices=SetupDiEnumDeviceInfo(devInfoSet, ++iLoop, &deviceInfoData);
  70. }
  71. // Release the device info list.
  72. SetupDiDestroyDeviceInfoList(devInfoSet);
  73. return count;
  74. }
  75. //
  76. // Unit-Test
  77. //
  78. //void __cdecl main()
  79. //{
  80. // ULONG count;
  81. // count = RDPDRINST_DetectInstall();
  82. // printf("Found %ld instance(s) of RDPDR.SYS.\n", count);
  83. //}