Can I get an example of the DNS WMI in C++

I need an example of the CreateZone method from the DNS WMI in C++. Please, I have been messing with this forever, and can not get it.

Below is a Vbscript implementation. I do however need it in C++. This is pretty urgent!!
Function CreateZone(strZoneName)
Dim ErrorCode
Dim objLocator, objSService
Dim objA
Dim objServer
Set objLocator = CreateObject("WbemScripting.SWbemLocator")
Set objSService = objLocator.ConnectServer(Application("strPServer"), "root\microsoftdns", Application("strLogin"), Application("strPass"))
Set objServer = objSService.Get("MicrosoftDNS_Server.name="".""")
objSService.Security_.ImpersonationLevel = 3
Set objA = objSService.Get("MicrosoftDNS_ZONE")
If Application("ServerOS") = "2000" Then
objA.CreateZone strZoneName, 1, , , ""
End If
If Application("ServerOS") = "2003" Then
objA.CreateZone strZoneName, 0, True
End If
Set objLocator = Nothing
Set objSService = Nothing
Set objA = Nothing
Set objServer = Nothing
If Err.Number <> 0 Then 
CreateZone = False
Else
CreateZone = True
End If
End Function

Open in new window

LVL 2
hilltopAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

trinitrotolueneDirector - Software EngineeringCommented:
suggest you take a look at the following documentation on MSDN. It lists out all the requisite methods needed for zoning....

http://msdn.microsoft.com/en-us/library/ms682757(VS.85).aspx

You need to create an instance of the MicrosoftDNS_Zone class. Once you create an object then you can call the functions that are provided by the MicrosoftDNS_Zone class.

the following link gives info on the createzone method.
http://msdn.microsoft.com/en-us/library/ms682760(VS.85).aspx
0
hilltopAuthor Commented:
I've been all over that stuff.
I cant even connect to the name space
Please help!


#define _WIN32_DCOM
#include "stdafx.h"
#include <iostream>
using namespace std;
#include <comdef.h>
#include <Wbemidl.h>
 
# pragma comment(lib, "wbemuuid.lib")
 
int main(int iArgCnt, char ** argv)
{
HRESULT hr;
hr = CoInitializeEx(0, COINIT_MULTITHREADED); 
if (FAILED(hr)) 
{ cout << "Failed to initialize COM library. Error code = 0x"
       << hex << hr << endl; 
  return hr;
}
 
hr =  CoInitializeSecurity(
    NULL,                      // Security descriptor    
    -1,                        // COM negotiates authentication service
    NULL,                      // Authentication services
    NULL,                      // Reserved
    RPC_C_AUTHN_LEVEL_DEFAULT, // Default authentication level for proxies
    RPC_C_IMP_LEVEL_IMPERSONATE, // Default Impersonation level for proxies
    NULL,                        // Authentication info
    EOAC_NONE,                   // Additional capabilities of the client or server
    NULL);                       // Reserved
 
if (FAILED(hr))
{
   cout << "Failed to initialize security. Error code = 0x" 
        << hex << hr << endl;
   CoUninitialize();
   return hr;                  // Program has failed.
}
 
    IWbemLocator *pLoc = 0;
   
 
    hr = CoCreateInstance(CLSID_WbemLocator, 0, 
        CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID *) &pLoc);
 
    if (FAILED(hr))
    {
        cout << "Failed to create IWbemLocator object. Err code = 0x"
             << hex << hr << endl;
        CoUninitialize();
        return hr;     // Program has failed.
    }
 
IWbemServices *pSvc = 0;
 
    // Connect to the root\default namespace with the current user.
    hr = pLoc->ConnectServer(
            BSTR(L"root\microsoftdns"), 
            NULL, NULL, 0, NULL, 0, 0, &pSvc);
 
    if (FAILED(hr))
    {
        cout << "Could not connect. Error code = 0x" 
             << hex << hr << endl;
        pLoc->Release();
        CoUninitialize();
        return hr;      // Program has failed.
    }
 
    cout << "Connected to WMI" << endl;
 
    CoUninitialize();
    return 0;
}

Open in new window

0
trinitrotolueneDirector - Software EngineeringCommented:
what is the exact error? and why are you using COM?
0
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

hilltopAuthor Commented:
Could not connect. Error code = 0x8004100e

This is on a machine that does have the provider installed. I can connect to other name spaces with the same code.
0
hilltopAuthor Commented:
You must use COM to access WMI in C++
0
trinitrotolueneDirector - Software EngineeringCommented:
Check whether you are loggin in as administrator

Also here's some more info on a problem with the host provider when Vista is used....
http://support.microsoft.com/kb/935553/

What is the OS you are running on?
0
trinitrotolueneDirector - Software EngineeringCommented:
>>>>>>>>>>>>>>>>>>BSTR(L"root\microsoftdns")


should it not be root\\microsoftdns

I guess the double slash is necessary to escape
0
trinitrotolueneDirector - Software EngineeringCommented:
here's some more interesting reading in case you were not aware of it earlier

http://msdn.microsoft.com/en-us/library/aa394558(VS.85).aspx
0
trinitrotolueneDirector - Software EngineeringCommented:
hello!!!

did it help
0
hilltopAuthor Commented:
Ive given up. I have already been over that stuff. I cannot even connect to the name space.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.