[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2008-11-13
10
Medium Priority
?
599 Views
Last Modified: 2012-05-05
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

0
Comment
Question by:hilltop
  • 6
  • 4
10 Comments
 
LVL 12

Expert Comment

by:trinitrotoluene
ID: 22958114
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
 
LVL 2

Author Comment

by:hilltop
ID: 22960820
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
 
LVL 12

Expert Comment

by:trinitrotoluene
ID: 22962460
what is the exact error? and why are you using COM?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 2

Author Comment

by:hilltop
ID: 22962502
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
 
LVL 2

Author Comment

by:hilltop
ID: 22962506
You must use COM to access WMI in C++
0
 
LVL 12

Expert Comment

by:trinitrotoluene
ID: 22967086
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
 
LVL 12

Expert Comment

by:trinitrotoluene
ID: 22967111
>>>>>>>>>>>>>>>>>>BSTR(L"root\microsoftdns")


should it not be root\\microsoftdns

I guess the double slash is necessary to escape
0
 
LVL 12

Expert Comment

by:trinitrotoluene
ID: 22967122
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
 
LVL 12

Assisted Solution

by:trinitrotoluene
trinitrotoluene earned 80 total points
ID: 23015577
hello!!!

did it help
0
 
LVL 2

Accepted Solution

by:
hilltop earned 0 total points
ID: 23015723
Ive given up. I have already been over that stuff. I cannot even connect to the name space.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question