SOL9 Sample: SWbemAntiSpywareProductQueryApplet

SOL9 2.0 Samples

1 Screenshot


2 Source code

/*
 * SWbemAntiSpywareProductQueryApplet.cpp 
 * Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */


//SOL9
// 2012/10/14

#include <sol/wmi/SWbemQueryApplet.h>


void _tmain(int argc, const TCHAR** argv)
{
  ApartmentThreadedModel apartmentThreaded;

  try {
    Locale locale;
    //1 Create a locator
    SOL::SWbemLocator locator;
    const BSTR server = L".";
    const BSTR namespaces[] = {L"ROOT\\SecurityCenter", L"ROOT\\SecurityCenter2"};
    const BSTR query = L"select * From AntiSpywareProduct";

    for (int n = 0; n<SizeOf(namespaces); n++) {
      //2 Connect to a server 
      SOL::SWbemServices services = locator.connectServer(server, namespaces[n]);
      printf("\nNamespace %S\n", namespaces[n]);

      //3 ExecQuery
      SOL::SWbemObjectSet objectSet= services.execQuery(query);

      //4 Display queryResult.
      long count = objectSet.getCount();

      for (long i = 0; i<count; i++) {
        try {
          SOL::SWbemObject object = objectSet.itemIndex(i);

          _bstr_t text = object.getObjectText(0);
          printf("%S\n", (const wchar_t*)text);

        } catch (...) {
        }   
      }
    }

  } catch (HRESULT hr) {
    printf("Exception HRESULT=%0x", hr); 
  } catch (Exception& ex) {
    ex.printf();
  } catch (...) {
    printf("Unknown IException\n");
  }
}

Last modified: 2 May 2016

Copyright (c) 2016 Antillia.com ALL RIGHTS RESERVED.