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.

142 lines
3.0 KiB

  1. /*++
  2. Copyright (c) 1997-1999 Microsoft Corporation
  3. Module Name:
  4. devinst.c
  5. Abstract:
  6. device instance id test
  7. Author:
  8. 16-Jan-1997 AlanWar
  9. Revision History:
  10. --*/
  11. #include <nt.h>
  12. #include <ntrtl.h>
  13. #include <nturtl.h>
  14. #include <windows.h>
  15. #include <ole2.h>
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include "wmium.h"
  19. #include "wmiguid.h"
  20. #define OffsetToPtr(Base, Offset) ((PBYTE)((PBYTE)(Base) + (Offset)))
  21. BYTE Buffer[4096];
  22. GUID InstanceInfoGuid = INSTANCE_INFO_GUID;
  23. void DumpCString(PCHAR What, PWCHAR String)
  24. {
  25. WCHAR Buf[MAX_PATH];
  26. ULONG Len;
  27. memset(Buf, 0, MAX_PATH);
  28. Len = *String++;
  29. memcpy(Buf, String, Len);
  30. printf("%s -> %ws\n", What, Buf);
  31. }
  32. void DumpBuffer(PWNODE_SINGLE_INSTANCE Wnode )
  33. {
  34. PWCHAR String;
  35. String = (PWCHAR)OffsetToPtr(Wnode, Wnode->DataBlockOffset);
  36. DumpCString("FriendlyName", String);
  37. String += (*String + sizeof(USHORT)) / sizeof(WCHAR);
  38. DumpCString("Description", String);
  39. String += (*String + sizeof(USHORT)) / sizeof(WCHAR);
  40. DumpCString("Location", String);
  41. String += (*String + sizeof(USHORT)) / sizeof(WCHAR);
  42. DumpCString("Manufacturer", String);
  43. String += (*String + sizeof(USHORT)) / sizeof(WCHAR);
  44. DumpCString("Service", String);
  45. String += (*String + sizeof(USHORT)) / sizeof(WCHAR);
  46. }
  47. void TestDevInst(
  48. void
  49. )
  50. /*
  51. Bad length
  52. bad out buffer
  53. bad input bufffer
  54. */
  55. {
  56. }
  57. int _cdecl main(int argc, char *argv[])
  58. {
  59. CHAR DevInstA[MAX_PATH];
  60. WMIHANDLE Handle;
  61. ULONG Status;
  62. ULONG SizeNeeded;
  63. ULONG BufLen;
  64. TestDevInst();
  65. if (argc == 1)
  66. {
  67. printf("devinst <device instance name>\n");
  68. return(0);
  69. }
  70. SizeNeeded = WmiDevInstToInstanceNameA(NULL,
  71. 0,
  72. argv[1],
  73. 0);
  74. printf("SizeNeedde (%s) -> %d\n", argv[1], SizeNeeded);
  75. SizeNeeded = WmiDevInstToInstanceNameA(DevInstA,
  76. SizeNeeded,
  77. argv[1],
  78. 0);
  79. printf("SizeNeedde (%s) -> %d\n", DevInstA, SizeNeeded);
  80. Status = WmiOpenBlock(&InstanceInfoGuid,
  81. 0,
  82. &Handle);
  83. if (Status != ERROR_SUCCESS)
  84. {
  85. printf("WmiOpenBlock -> %d\n", Status);
  86. } else {
  87. BufLen = sizeof(Buffer);
  88. Status = WmiQuerySingleInstance(Handle,
  89. DevInstA,
  90. &BufLen,
  91. (PVOID)Buffer);
  92. if (Status != ERROR_SUCCESS)
  93. {
  94. printf("WmiQuerySingleInstance -> %d\n", Status);
  95. } else {
  96. DumpBuffer((PWNODE_SINGLE_INSTANCE)Buffer);
  97. }
  98. WmiCloseBlock(Handle);
  99. }
  100. return(ERROR_SUCCESS);
  101. }