Code snippet Using WMI via C++/CLI

#include "stdafx.h"
#using < system.management.dll>
using
namespace System;
using namespace System::Management; 
int
main(array<System::String ^> ^args)
{
    Console::WriteLine(L"Query
processor count via CLI by Onega");
    ConnectionOptions^ options = gcnew
ConnectionOptions();
    //options->Password = L"";
   
//options->Username = L"";
    //options->Authority = "NTLMDomain:"
;
    options->Impersonation = ImpersonationLevel::Impersonate;
   
ManagementScope^ scope = gcnew
ManagementScope("\\\\localhost\\root\\CIMV2",options);
    SelectQuery^
processorquery = gcnew SelectQuery("SELECT * FROM WIN32_Processor ");
   
ManagementObjectSearcher^ query = gcnew ManagementObjectSearcher(scope,
processorquery);
    ManagementObjectCollection^ resultcollection =
query->Get();
    ManagementObjectCollection::ManagementObjectEnumerator^
enu = resultcollection->GetEnumerator();
    int processor_count =
0;
    while(enu->MoveNext())
    {
       
Console::WriteLine(enu->Current->ToString());
       
processor_count++;
    }
    Console::WriteLine(L"Processor count:{0}",
processor_count);
    return 0;
}

Advertisements
This entry was posted in MFC. Bookmark the permalink.

One Response to Code snippet Using WMI via C++/CLI

  1. Mike T. says:

    Awesome! Thank you!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s