Advertisement
Guest User

Untitled

a guest
Dec 11th, 2018
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 15.94 KB | None | 0 0
  1. #include <iostream>
  2. #include <comdef.h>
  3. #include <Wbemidl.h>
  4. #include <wincred.h>
  5. #include <strsafe.h>
  6. #include <conio.h>
  7. #pragma comment(lib, "wbemuuid.lib")
  8. #pragma comment(lib, "credui.lib")
  9. #pragma comment(lib, "comsuppw.lib")
  10. #define _WIN32_DCOM
  11. #define UNICODE
  12. using namespace std;
  13.  
  14. int __cdecl main(int argc, char **argv)
  15. {
  16.     setlocale(LC_ALL, "");
  17.     HRESULT hres;
  18.     // Шаг 1: --------------------------------------------------
  19.     // Инициализация COM. ------------------------------------------
  20.     hres = CoInitializeEx(0, COINIT_MULTITHREADED);
  21.     if (FAILED(hres))
  22.     {
  23.         cout << "Failed to initialize COM library. Error code = 0x"
  24.             << hex << hres << endl;
  25.         return 1;
  26.     }
  27.     // Шаг 2: --------------------------------------------------
  28.     // Установка уровней безопасности COM --------------------------
  29.     hres = CoInitializeSecurity(
  30.         NULL,
  31.         -1,
  32.         NULL,
  33.         NULL,
  34.         RPC_C_AUTHN_LEVEL_DEFAULT,
  35.         RPC_C_IMP_LEVEL_IDENTIFY,
  36.         NULL,
  37.         EOAC_NONE,
  38.         NULL
  39.     );
  40.     if (FAILED(hres))
  41.     {
  42.         cout << "Failed to initialize security. Error code = 0x"
  43.             << hex << hres << endl;
  44.         CoUninitialize();
  45.         return 1;
  46.     }
  47.     // Шаг 3: ---------------------------------------------------
  48.     // Создание локатора WMI -------------------------
  49.     IWbemLocator *pLoc = NULL;
  50.     hres = CoCreateInstance(
  51.         CLSID_WbemLocator,
  52.         0,
  53.         CLSCTX_INPROC_SERVER,
  54.         IID_IWbemLocator, (LPVOID *)&pLoc);
  55.     if (FAILED(hres))
  56.     {
  57.         cout << "Failed to create IWbemLocator object."
  58.             << " Err code = 0x"
  59.             << hex << hres << endl;
  60.         CoUninitialize();
  61.         return 1;
  62.     }
  63.     // Шаг 4: -----------------------------------------------------
  64.     // Подключение к WMI через IWbemLocator::ConnectServer
  65.     IWbemServices *pSvc = NULL;
  66.     // Получение реквизитов доступа к удаленному компьютеру
  67.     CREDUI_INFO cui;
  68.     bool useToken = false;
  69.     bool useNTLM = true;
  70.     wchar_t pszName[CREDUI_MAX_USERNAME_LENGTH + 1] = { 0 };
  71.     wchar_t pszPwd[CREDUI_MAX_PASSWORD_LENGTH + 1] = { 0 };
  72.     wchar_t pszDomain[CREDUI_MAX_USERNAME_LENGTH + 1];
  73.     wchar_t pszUserName[CREDUI_MAX_USERNAME_LENGTH + 1];
  74.     wchar_t pszAuthority[CREDUI_MAX_USERNAME_LENGTH + 1];
  75.     BOOL fSave;
  76.     DWORD dwErr;
  77.     memset(&cui, 0, sizeof(CREDUI_INFO));
  78.     cui.cbSize = sizeof(CREDUI_INFO);
  79.     cui.hwndParent = NULL;
  80.     cui.pszMessageText = TEXT("Press cancel to use process token");
  81.     cui.pszCaptionText = TEXT("Enter Account Information");
  82.     cui.hbmBanner = NULL;
  83.     fSave = FALSE;
  84.     dwErr = CredUIPromptForCredentials(
  85.         &cui,
  86.         TEXT(""),
  87.         NULL,
  88.         0,
  89.         pszName,
  90.         CREDUI_MAX_USERNAME_LENGTH + 1,
  91.         pszPwd,
  92.         CREDUI_MAX_PASSWORD_LENGTH + 1,
  93.         &fSave,
  94.         CREDUI_FLAGS_GENERIC_CREDENTIALS |
  95.         CREDUI_FLAGS_ALWAYS_SHOW_UI |
  96.         CREDUI_FLAGS_DO_NOT_PERSIST);
  97.     if (dwErr == ERROR_CANCELLED)
  98.     {
  99.         useToken = true;
  100.  
  101.     }
  102.     else if (dwErr)
  103.     {
  104.         cout << "Did not get credentials " << dwErr << endl;
  105.         pLoc->Release();
  106.         CoUninitialize();
  107.         return 1;
  108.     }
  109.     // change the computerName strings below to the full computer name
  110.     // of the remote computer
  111.     if (!useNTLM)
  112.     {
  113.         StringCchPrintf(pszAuthority, CREDUI_MAX_USERNAME_LENGTH + 1,
  114.             //L"kERBEROS:%s", L"WIN-HQPJIBBHJTC");
  115.             L"kERBEROS:%s", L"WIN-HQPJIBBHJTC");
  116.     }
  117.     // Подключение к пространству имен root\cimv2
  118.     //---------------------------------------------------------
  119.     hres = pLoc->ConnectServer(
  120.         //_bstr_t(L"\\\\WIN-HQPJIBBHJTC\\root\\cimv2"),
  121.         _bstr_t(L"\\\\WIN-HQPJIBBHJTC\\root\\SecurityCenter2"),
  122.         _bstr_t(useToken ? NULL : pszName),
  123.         _bstr_t(useToken ? NULL : pszPwd),
  124.         NULL,
  125.         NULL,
  126.         _bstr_t(useNTLM ? NULL : pszAuthority),
  127.         NULL,
  128.         &pSvc
  129.     );
  130.     if (FAILED(hres))
  131.     {
  132.         cout << "Could not connect. Error code = 0x"
  133.             << hex << hres << endl;
  134.         pLoc->Release();
  135.         CoUninitialize();
  136.         return 1;
  137.     }
  138.     cout << "Connected to ROOT\\SecurityCenter2 WMI namespace" << endl;
  139.     // Шаг 5: --------------------------------------------------
  140.     // Создание структуры COAUTHIDENTITY
  141.     COAUTHIDENTITY *userAcct = NULL;
  142.     COAUTHIDENTITY authIdent;
  143.     if (!useToken)
  144.     {
  145.         memset(&authIdent, 0, sizeof(COAUTHIDENTITY));
  146.         authIdent.PasswordLength = wcslen(pszPwd);
  147.         authIdent.Password = (USHORT*)pszPwd;
  148.         LPWSTR slash = wcschr(pszName, L'\\');
  149.         if (slash == NULL)
  150.         {
  151.             cout << "Could not create Auth identity. No domain specified\n";
  152.             pSvc->Release();
  153.             pLoc->Release();
  154.             CoUninitialize();
  155.             return 1;
  156.         }
  157.         StringCchCopy(pszUserName, CREDUI_MAX_USERNAME_LENGTH + 1, slash + 1);
  158.         authIdent.User = (USHORT*)pszUserName;
  159.         authIdent.UserLength = wcslen(pszUserName);
  160.         StringCchCopyN(pszDomain, CREDUI_MAX_USERNAME_LENGTH + 1, pszName,
  161.             slash - pszName);
  162.         authIdent.Domain = (USHORT*)pszDomain;
  163.         authIdent.DomainLength = slash - pszName;
  164.         authIdent.Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE;
  165.         userAcct = &authIdent;
  166.     }
  167.     // Шаг 6: --------------------------------------------------
  168.     // Установка защиты прокси сервера ------------------
  169.     hres = CoSetProxyBlanket(
  170.         pSvc,
  171.         RPC_C_AUTHN_DEFAULT,
  172.         RPC_C_AUTHZ_DEFAULT,
  173.         COLE_DEFAULT_PRINCIPAL,
  174.         RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
  175.         RPC_C_IMP_LEVEL_IMPERSONATE,
  176.         userAcct,
  177.         EOAC_NONE
  178.     );
  179.     if (FAILED(hres))
  180.     {
  181.         cout << "Could not set proxy blanket. Error code = 0x"
  182.             << hex << hres << endl;
  183.         pSvc->Release();
  184.         pLoc->Release();
  185.         CoUninitialize();
  186.         return 1;
  187.     }
  188.     // Шаг 7: --------------------------------------------------
  189.     // Получение данных через WMI ----
  190.     // Например, получим имя ОС
  191.     IEnumWbemClassObject * pEnumerator = NULL, * pEnumerator2 = NULL, * pEnumerator3 = NULL;
  192.     hres = pSvc->ExecQuery(
  193.         bstr_t("WQL"),
  194.         bstr_t("Select * from AntivirusProduct"),
  195.         WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
  196.         NULL,
  197.         &pEnumerator);
  198.     hres = pSvc->ExecQuery(
  199.         bstr_t("WQL"),
  200.         bstr_t("Select * from AntiSpywareProduct"),
  201.         WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
  202.         NULL,
  203.         &pEnumerator2);
  204.     hres = pSvc->ExecQuery(
  205.         bstr_t("WQL"),
  206.         bstr_t("Select * from FirewallProduct"),
  207.         WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
  208.         NULL,
  209.         &pEnumerator3);
  210.     if (FAILED(hres))
  211.     {
  212.         cout << "Query for operating system name failed."
  213.             << " Error code = 0x"
  214.             << hex << hres << endl;
  215.         pSvc->Release();
  216.         pLoc->Release();
  217.         CoUninitialize();
  218.         return 1;
  219.     }
  220.     hres = CoSetProxyBlanket(
  221.         pEnumerator,
  222.         RPC_C_AUTHN_DEFAULT,
  223.         RPC_C_AUTHZ_DEFAULT,
  224.         COLE_DEFAULT_PRINCIPAL,
  225.         RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
  226.         RPC_C_IMP_LEVEL_IMPERSONATE,
  227.         userAcct,
  228.         EOAC_NONE
  229.     );
  230.     hres = CoSetProxyBlanket(
  231.         pEnumerator2,
  232.         RPC_C_AUTHN_DEFAULT,
  233.         RPC_C_AUTHZ_DEFAULT,
  234.         COLE_DEFAULT_PRINCIPAL,
  235.         RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
  236.         RPC_C_IMP_LEVEL_IMPERSONATE,
  237.         userAcct,
  238.         EOAC_NONE
  239.     );
  240.     hres = CoSetProxyBlanket(
  241.         pEnumerator3,
  242.         RPC_C_AUTHN_DEFAULT,
  243.         RPC_C_AUTHZ_DEFAULT,
  244.         COLE_DEFAULT_PRINCIPAL,
  245.         RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
  246.         RPC_C_IMP_LEVEL_IMPERSONATE,
  247.         userAcct,
  248.         EOAC_NONE
  249.     );
  250.     if (FAILED(hres))
  251.     {
  252.         cout << "Could not set proxy blanket on enumerator. Error code = 0x"
  253.             << hex << hres << endl;
  254.         pEnumerator->Release();
  255.         pSvc->Release();
  256.         pLoc->Release();
  257.         CoUninitialize();
  258.         return 1;
  259.     }
  260.     // Шаг 9: -------------------------------------------------
  261.     // Получение данных из запроса в шаге 7 -------------------
  262.     IWbemClassObject *pclsObj = NULL, *pclsObj2 = NULL, *pclsObj3 = NULL;
  263.     ULONG uReturn = 0;
  264.     while (pEnumerator)
  265.     {
  266.         HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1,
  267.             &pclsObj, &uReturn);
  268.         if (0 == uReturn)
  269.         {
  270.             break;
  271.         }
  272.         VARIANT vtProp;
  273.         // Выбираем поле Name
  274.         hr = pclsObj->Get(L"displayName", 0, &vtProp, 0, 0);
  275.         wcout << "Antivirus: " << endl << " Name : " << vtProp.bstrVal << endl;
  276.         hr = pclsObj->Get(L"instanceGuid", 0, &vtProp, 0, 0);
  277.         wcout << " Instance Guid : " << vtProp.bstrVal << endl;
  278.         VariantClear(&vtProp);
  279.         pclsObj->Release();
  280.         pclsObj = NULL;
  281.     }
  282.     while (pEnumerator2)
  283.     {
  284.         HRESULT hr2 = pEnumerator2->Next(WBEM_INFINITE, 1,
  285.             &pclsObj2, &uReturn);
  286.         if (0 == uReturn)
  287.         {
  288.             break;
  289.         }
  290.         VARIANT vtProp;
  291.         // Выбираем поле Name
  292.         hr2 = pclsObj2->Get(L"displayName", 0, &vtProp, 0, 0);
  293.         wcout << "Antispyware:" << endl << " Name : " << vtProp.bstrVal << endl;
  294.         hr2 = pclsObj2->Get(L"pathToSignedProductExe", 0, &vtProp, 0, 0);
  295.         wcout << " Path To Signed Product Exe : " << vtProp.bstrVal << endl;
  296.         VariantClear(&vtProp);
  297.         pclsObj2->Release();
  298.         pclsObj2 = NULL;
  299.     }
  300.     while (pEnumerator3)
  301.     {
  302.         HRESULT hr3 = pEnumerator3->Next(WBEM_INFINITE, 1,
  303.             &pclsObj3, &uReturn);
  304.         if (0 == uReturn)
  305.         {
  306.             break;
  307.         }
  308.         VARIANT vtProp;
  309.         // Выбираем поле Name
  310.         hr3 = pclsObj3->Get(L"displayName", 0, &vtProp, 0, 0);
  311.         wcout << " Firewall Name : " << vtProp.bstrVal << endl;
  312.         //hr3 = pclsObj3->Get(L"pathToSignedProductExe", 0, &vtProp, 0, 0);
  313.         //wcout << " Firewall pathToSignedProductExe : " << vtProp.bstrVal << endl;
  314.         VariantClear(&vtProp);
  315.         pclsObj3->Release();
  316.         pclsObj3 = NULL;
  317.     }
  318.  
  319.     HRESULT hres1;
  320.     // Шаг 3: ---------------------------------------------------
  321.     // Создание локатора WMI -------------------------
  322.     IWbemLocator *pLoc1 = NULL;
  323.     hres1 = CoCreateInstance(
  324.         CLSID_WbemLocator,
  325.         0,
  326.         CLSCTX_INPROC_SERVER,
  327.         IID_IWbemLocator, (LPVOID *)&pLoc1);
  328.     if (FAILED(hres1))
  329.     {
  330.         cout << "Failed to create IWbemLocator object."
  331.             << " Err code = 0x"
  332.             << hex << hres1 << endl;
  333.         CoUninitialize();
  334.         return 1;
  335.     }
  336.     // Шаг 4: -----------------------------------------------------
  337.     // Подключение к WMI через IWbemLocator::ConnectServer
  338.     IWbemServices *pSvc1 = NULL;
  339.     // Получение реквизитов доступа к удаленному компьютеру
  340.  
  341.     // change the computerName strings below to the full computer name
  342.     // of the remote computer
  343.     if (!useNTLM)
  344.     {
  345.         StringCchPrintf(pszAuthority, CREDUI_MAX_USERNAME_LENGTH + 1,
  346.             //L"kERBEROS:%s", L"WIN-HQPJIBBHJTC");
  347.             L"kERBEROS:%s", L"WIN-HQPJIBBHJTC");
  348.     }
  349.     // Подключение к пространству имен root\cimv2
  350.     //---------------------------------------------------------
  351.     hres1 = pLoc1->ConnectServer(
  352.         //_bstr_t(L"\\\\WIN-HQPJIBBHJTC\\root\\cimv2"),
  353.         _bstr_t(L"\\\\WIN-HQPJIBBHJTC\\root\\cimv2"),
  354.         _bstr_t(useToken ? NULL : pszName),
  355.         _bstr_t(useToken ? NULL : pszPwd),
  356.         NULL,
  357.         NULL,
  358.         _bstr_t(useNTLM ? NULL : pszAuthority),
  359.         NULL,
  360.         &pSvc1
  361.     );
  362.     if (FAILED(hres1))
  363.     {
  364.         cout << "Could not connect. Error code = 0x"
  365.             << hex << hres1 << endl;
  366.         pLoc1->Release();
  367.         CoUninitialize();
  368.         return 1;
  369.     }
  370.     cout << endl << "Connected to ROOT\\CIMV2 WMI namespace" << endl;
  371.     // Шаг 5: --------------------------------------------------
  372.     // Создание структуры COAUTHIDENTITY
  373.     //IWbemServices *pSvc1 = NULL;
  374.     COAUTHIDENTITY *userAcct1 = NULL;
  375.     COAUTHIDENTITY authIdent1;
  376.     if (!useToken)
  377.     {
  378.         memset(&authIdent1, 0, sizeof(COAUTHIDENTITY));
  379.         authIdent1.PasswordLength = wcslen(pszPwd);
  380.         authIdent1.Password = (USHORT*)pszPwd;
  381.         LPWSTR slash = wcschr(pszName, L'\\');
  382.         if (slash == NULL)
  383.         {
  384.             cout << "Could not create Auth identity. No domain specified\n";
  385.             pSvc1->Release();
  386.             pLoc1->Release();
  387.             CoUninitialize();
  388.             return 1;
  389.         }
  390.         StringCchCopy(pszUserName, CREDUI_MAX_USERNAME_LENGTH + 1, slash + 1);
  391.         authIdent1.User = (USHORT*)pszUserName;
  392.         authIdent1.UserLength = wcslen(pszUserName);
  393.         StringCchCopyN(pszDomain, CREDUI_MAX_USERNAME_LENGTH + 1, pszName,
  394.             slash - pszName);
  395.         authIdent1.Domain = (USHORT*)pszDomain;
  396.         authIdent1.DomainLength = slash - pszName;
  397.         authIdent1.Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE;
  398.         userAcct1 = &authIdent;
  399.     }
  400.     // Шаг 6: --------------------------------------------------
  401.     // Установка защиты прокси сервера ------------------
  402.     hres1 = CoSetProxyBlanket(
  403.         pSvc1,
  404.         RPC_C_AUTHN_DEFAULT,
  405.         RPC_C_AUTHZ_DEFAULT,
  406.         COLE_DEFAULT_PRINCIPAL,
  407.         RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
  408.         RPC_C_IMP_LEVEL_IMPERSONATE,
  409.         userAcct1,
  410.         EOAC_NONE
  411.     );
  412.     if (FAILED(hres1))
  413.     {
  414.         cout << "Could not set proxy blanket. Error code = 0x"
  415.             << hex << hres1 << endl;
  416.         pSvc1->Release();
  417.         pLoc1->Release();
  418.         CoUninitialize();
  419.         return 1;
  420.     }
  421.     // Шаг 7: --------------------------------------------------
  422.     // Получение данных через WMI ----
  423.     // Например, получим имя ОС
  424.     IEnumWbemClassObject* pEnumerator1 = NULL, * pEnumerator1_1 = NULL;
  425.     hres1 = pSvc1->ExecQuery(
  426.         bstr_t("WQL"),
  427.         bstr_t("Select * from Win32_OperatingSystem"),
  428.         WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
  429.         NULL,
  430.         &pEnumerator1);
  431.     hres1 = pSvc1->ExecQuery(
  432.         bstr_t("WQL"),
  433.         bstr_t("Select * from Win32_Product"),
  434.         WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
  435.         NULL,
  436.         &pEnumerator1_1);
  437.     if (FAILED(hres1))
  438.     {
  439.         cout << "Query for operating system name failed."
  440.             << " Error code = 0x"
  441.             << hex << hres1 << endl;
  442.         pSvc1->Release();
  443.         pLoc1->Release();
  444.         CoUninitialize();
  445.         return 1;
  446.     }
  447.     hres1 = CoSetProxyBlanket(
  448.         pEnumerator1,
  449.         RPC_C_AUTHN_DEFAULT,
  450.         RPC_C_AUTHZ_DEFAULT,
  451.         COLE_DEFAULT_PRINCIPAL,
  452.         RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
  453.         RPC_C_IMP_LEVEL_IMPERSONATE,
  454.         userAcct1,
  455.         EOAC_NONE
  456.     );
  457.     hres1 = CoSetProxyBlanket(
  458.         pEnumerator1_1,
  459.         RPC_C_AUTHN_DEFAULT,
  460.         RPC_C_AUTHZ_DEFAULT,
  461.         COLE_DEFAULT_PRINCIPAL,
  462.         RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
  463.         RPC_C_IMP_LEVEL_IMPERSONATE,
  464.         userAcct1,
  465.         EOAC_NONE
  466.     );
  467.     if (FAILED(hres1))
  468.     {
  469.         cout << "Could not set proxy blanket on enumerator. Error code = 0x"
  470.             << hex << hres1 << endl;
  471.         pEnumerator1->Release();
  472.         pSvc1->Release();
  473.         pLoc1->Release();
  474.         CoUninitialize();
  475.         return 1;
  476.     }
  477.     SecureZeroMemory(pszName, sizeof(pszName));
  478.     SecureZeroMemory(pszPwd, sizeof(pszPwd));
  479.     SecureZeroMemory(pszUserName, sizeof(pszUserName));
  480.     SecureZeroMemory(pszDomain, sizeof(pszDomain));
  481.     // Шаг 9: -------------------------------------------------
  482.     // Получение данных из запроса в шаге 7 -------------------
  483.     IWbemClassObject *pclsObj1 = NULL;
  484.     ULONG uReturn1 = 0;
  485.     while (pEnumerator1)
  486.     {
  487.         HRESULT hr1 = pEnumerator1->Next(WBEM_INFINITE, 1,
  488.             &pclsObj1, &uReturn1);
  489.         if (0 == uReturn1)
  490.         {
  491.             break;
  492.         }
  493.         VARIANT vtProp1;
  494.         //OS Name
  495.         hr1 = pclsObj1->Get(L"Caption", 0, &vtProp1, 0, 0);
  496.         wcout << " OS Name : " << vtProp1.bstrVal << endl;
  497.         //RegisteredUser
  498.         hr1 = pclsObj1->Get(L"RegisteredUser", 0, &vtProp1, 0, 0);
  499.         wcout << " Registered User : " << vtProp1.bstrVal << endl;
  500.         //BootDevice
  501.         hr1 = pclsObj1->Get(L"BootDevice", 0, &vtProp1, 0, 0);
  502.         wcout << " Boot Device : " << vtProp1.bstrVal << endl;
  503.         //SystemDevice
  504.         hr1 = pclsObj1->Get(L"SystemDevice", 0, &vtProp1, 0, 0);
  505.         wcout << " System Device : " << vtProp1.bstrVal << endl;
  506.         //SerialNumber
  507.         hr1 = pclsObj1->Get(L"SerialNumber", 0, &vtProp1, 0, 0);
  508.         wcout << " Serial Number : " << vtProp1.bstrVal << endl;
  509.         //BuildNumber
  510.         hr1 = pclsObj1->Get(L"BuildNumber", 0, &vtProp1, 0, 0);
  511.         wcout << " Build Number : " << vtProp1.bstrVal << endl;
  512.         //OSArchitecture
  513.         hr1 = pclsObj1->Get(L"OSArchitecture", 0, &vtProp1, 0, 0);
  514.         wcout << " OS Architecture : " << vtProp1.bstrVal << endl << endl;
  515.  
  516.         VariantClear(&vtProp1);
  517.         pclsObj1->Release();
  518.         pclsObj1 = NULL;
  519.     }
  520.     IWbemClassObject *pclsObj1_1 = NULL;
  521.     uReturn1 = 0;
  522.     wcout << "Programs Name : " << endl;
  523.     while (pEnumerator1_1)
  524.     {
  525.         HRESULT hr1 = pEnumerator1_1->Next(WBEM_INFINITE, 1,
  526.             &pclsObj1_1, &uReturn1);
  527.         if (0 == uReturn1)
  528.         {
  529.             break;
  530.         }
  531.         VARIANT vtProp1;
  532.         // Выбираем поле Name
  533.         hr1 = pclsObj1_1->Get(L"Name", 0, &vtProp1, 0, 0);
  534.         wcout << " "<< vtProp1.bstrVal << endl;
  535.         VariantClear(&vtProp1);
  536.         pclsObj1_1->Release();
  537.         pclsObj1_1 = NULL;
  538.     }
  539.  
  540.     // Очистка
  541.     // ========
  542.     pSvc1->Release();
  543.     pLoc1->Release();
  544.     pEnumerator1->Release();
  545.     if (pclsObj1)
  546.     {
  547.         pclsObj1->Release();
  548.     }
  549.     CoUninitialize();
  550.     _getch();
  551.     return 0;
  552. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement