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.

133 lines
3.0 KiB

  1. #include <windows.h>
  2. #include <ole2.h>
  3. #include <appmgmt.h>
  4. #include <stdlib.h>
  5. #include <stdio.h>
  6. void
  7. GuidToString(
  8. GUID & Guid,
  9. PWCHAR pwszGuid
  10. )
  11. {
  12. wsprintf(
  13. pwszGuid,
  14. L"{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
  15. Guid.Data1,
  16. Guid.Data2,
  17. Guid.Data3,
  18. Guid.Data4[0],
  19. Guid.Data4[1],
  20. Guid.Data4[2],
  21. Guid.Data4[3],
  22. Guid.Data4[4],
  23. Guid.Data4[5],
  24. Guid.Data4[6],
  25. Guid.Data4[7]
  26. );
  27. }
  28. void
  29. StringToGuid(
  30. PCHAR pszGuid,
  31. GUID * pGuid
  32. )
  33. {
  34. WCHAR wszGuid[256];
  35. wsprintf((WCHAR*)wszGuid, L"%S", pszGuid);
  36. CLSIDFromString(wszGuid, pGuid);
  37. }
  38. void __cdecl main(int argc, char** argv)
  39. {
  40. LONG Error;
  41. PMANAGEDAPPLICATION rgApps;
  42. DWORD dwApps;
  43. GUID CategoryGuid;
  44. GUID* pCategory = NULL;
  45. if (argc >= 2) {
  46. StringToGuid(argv[1], &CategoryGuid);
  47. pCategory = &CategoryGuid;
  48. printf("Listed apps will come from category %s\n", argv[1]);
  49. }
  50. Error = GetManagedApplications(
  51. pCategory,
  52. pCategory ? MANAGED_APPS_FROMCATEGORY : MANAGED_APPS_USERAPPLICATIONS,
  53. MANAGED_APPS_INFOLEVEL_DEFAULT,
  54. &dwApps,
  55. &rgApps);
  56. if (ERROR_SUCCESS == Error) {
  57. printf("GetManagedApplications SUCCEEDED\n");
  58. printf("Returned %d Apps\n", dwApps);
  59. for (DWORD dwApp = 0; dwApp < dwApps; dwApp ++)
  60. {
  61. WCHAR wszGuid[256];
  62. PMANAGEDAPPLICATION pApp;
  63. pApp = &(rgApps[dwApp]);
  64. printf("\nApp: %ls\n", rgApps[dwApp].pszPackageName);
  65. printf("Publisher: %ls\n", pApp->pszPublisher);
  66. printf("Revison: %d.%d build %d\n", pApp->dwVersionHi, pApp->dwVersionLo, pApp->dwRevision);
  67. printf("Support URL: %ls\n", rgApps[dwApp].pszSupportUrl);
  68. printf("GPO Name: %ls\n", rgApps[dwApp].pszPolicyName);
  69. GuidToString(rgApps[dwApp].GpoId, wszGuid);
  70. printf("GPO: %ls\n", wszGuid);
  71. fflush(stdin);
  72. GuidToString(rgApps[dwApp].ProductId, wszGuid);
  73. printf("Product: %ls\n", wszGuid);
  74. fflush(stdin);
  75. printf("App Path Type ");
  76. switch (rgApps[dwApp].dwPathType)
  77. {
  78. case MANAGED_APPTYPE_WINDOWSINSTALLER:
  79. printf("Darwin\n");
  80. break;
  81. case MANAGED_APPTYPE_SETUPEXE:
  82. printf("Crappy ZAW\n");
  83. break;
  84. case MANAGED_APPTYPE_UNSUPPORTED:
  85. printf("Unsupported\n");
  86. break;
  87. default:
  88. printf("INVALID\n");
  89. }
  90. fflush(stdin);
  91. }
  92. LocalFree(rgApps);
  93. } else {
  94. printf("GetManagedApplications returned %x\n", Error);
  95. }
  96. }