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.

126 lines
2.0 KiB

  1. #include <windows.h>
  2. #include <ole2.h>
  3. #include <stdio.h>
  4. void _cdecl main(int argc, char *argv[])
  5. {
  6. IRunningObjectTable *prot = NULL;
  7. HRESULT hr;
  8. IBindCtx *pbc = NULL;
  9. IEnumMoniker * penumMoniker = NULL;
  10. IMoniker *alpMonikers[100];
  11. DWORD dwReturned;
  12. DWORD dwTotalCount = 0;
  13. BOOL fFlushROT = FALSE;
  14. hr = CoInitialize(NULL);
  15. if (FAILED(hr))
  16. {
  17. printf("CoInitialize fails %x\n",hr);
  18. exit(-1);
  19. }
  20. if ((argc == 2) && strcmp(argv[1],"-f"))
  21. {
  22. printf("Valid flags are -f for flush\n");
  23. goto exitNow;
  24. }
  25. if( argc == 2)
  26. {
  27. fFlushROT = TRUE;
  28. printf("Flushing ROT as we go!\n");
  29. }
  30. hr = GetRunningObjectTable(0,&prot);
  31. if (FAILED(hr))
  32. {
  33. printf("Get ROT failed! %x\n",hr);
  34. goto exitNow;
  35. }
  36. hr = prot->EnumRunning(&penumMoniker);
  37. if (FAILED(hr))
  38. {
  39. printf("Enum ROT has failed %x\n",hr);
  40. goto exitNow;
  41. }
  42. hr = CreateBindCtx(0,&pbc);
  43. if(FAILED(hr))
  44. {
  45. printf("CreateBindContext returned %x\n",hr);
  46. goto exitNow;
  47. }
  48. do
  49. {
  50. hr = penumMoniker->Next(100,alpMonikers,&dwReturned);
  51. if(FAILED(hr))
  52. {
  53. printf("penumMoniker->Next failed %x\n",hr);
  54. goto exitNow;
  55. }
  56. for (DWORD i = 0 ; i < dwReturned ; i++)
  57. {
  58. LPWSTR pwcName;
  59. if(alpMonikers[i] == NULL) continue;
  60. hr = alpMonikers[i]->GetDisplayName(pbc,NULL,&pwcName);
  61. if(FAILED(hr))
  62. {
  63. printf("** MONIKER %x RETURNED ERRORCODE %x",i,hr);
  64. }
  65. else
  66. {
  67. printf("%S",pwcName);
  68. CoTaskMemFree(pwcName);
  69. }
  70. if(fFlushROT)
  71. {
  72. IUnknown *punk;
  73. hr = prot->GetObject(alpMonikers[i],&punk);
  74. if(FAILED(hr))
  75. {
  76. printf(" Flushed (hr=0x%x)",hr);
  77. }
  78. else
  79. {
  80. printf(" Connected. Releasing connection");
  81. }
  82. }
  83. printf("\n");
  84. alpMonikers[i]->Release();
  85. }
  86. dwTotalCount += dwReturned;
  87. } while(dwReturned == 100);
  88. printf("** Total number of entries is %u\n",dwTotalCount);
  89. exitNow:
  90. if(prot != NULL)
  91. {
  92. prot->Release();
  93. }
  94. if(penumMoniker != NULL)
  95. {
  96. penumMoniker->Release();
  97. }
  98. if(pbc != NULL)
  99. {
  100. pbc->Release();
  101. }
  102. CoUninitialize();
  103. }