Title: Message
And don't even think about the bugs and memory leaks!
 
-gil
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Michael B. Smith
Sent: Tuesday, October 28, 2003 1:36 PM
To: [EMAIL PROTECTED]
Subject: [ActiveDir] DNS WMI Provider

OK, I just gotta share, to vent some of my frustration.
 
The DNS provider on Windows 2000 (included in the resource kit supplement and available for download from Microsoft) is NOT compatible with the DNS provider on Window 2003! Dagnabit! The CreateZone() and the WriteBackZone() routines are different!!
 
And the documentation on MSDN isn't right -- it's somewhere in between the two versions.
 
To figure it out, I eventually had to go into the blasted MOF files. Silly.
 
VERY silly.
 
And secondly, pass-through authentication does not work with WMI. Whose idea was THAT one?
 
Bah. Humbug.
 
So, because of these two things, I've gotta have code like this:
 
Const int2000ADZone        = 0
Const int2000PrimaryZone   = 1
Const int2000SecondaryZone = 2
 
Const int2003PrimaryZone   = 0
Const int2003SecondaryZone = 1
Const int2003StubZone      = 2
Const int2003ForwardZone   = 3
'
' code
'

Sub CreateTheZone (objZoneRef, strZoneName)
 ' Create the Zone
 Dim errResult
 
 WScript.Echo "Creating zone " & strZoneName
 If intOS = 2000 Then
  errResult = objZoneRef.CreateZone (strZoneName, int2000PrimaryZone)
 Else
  'intOS = 2003
  errResult = objZoneRef.CreateZone (strZoneName, int2003PrimaryZone, False)
 End If
 
 WScript.Echo "Created zone " & strZoneName & ", will now create resource records"
End Sub
 
Sub SaveTheZone (objWMI, strZoneName)
 ' Write the zone back to disk
 
 Dim objZone, objZones
 
 WScript.Echo "Updating disk image of zone"
 set objZones = objWMI.ExecQuery ("Select * from MicrosoftDNS_Zone " & _
     "where ContainerName = '" & strZoneName & "'")
 For Each objZone in objZones
  If intOS = 2000 Then
   objZone.WriteBackZoneToFile ()
  Else
   ' intOS = 2003
   objZone.WriteBackZone ()
  End If
 Next
 WScript.Echo "Disk image updated"
End Sub
Function OSVersion (strUser, strPass, strServer)
 Dim colOS, objOS, strCaption, intOSver, objWMI
 
 intOSver = -1
 
 If ConnectComputer (strUser, strPass, strServer, "root\cimv2", objWMI) Then
  Wscript.Echo "*** Error: Could not connect to CIMv2 namespace on " & strServer
  WScript.Quit 1
 End If
 
 Set colOS = objWMI.ExecQuery ("Select * from Win32_OperatingSystem")
 For Each objOS in colOS
  'Wscript.Echo objOS.Caption ' & " " & objOS.Version
  strCaption = objOS.Caption
  If Instr (strCaption, "2000") Then
   intOSver = 2000
  Else
   If Instr (strcaption, "2003") Then
    intOSver = 2003
   End If
  End If
  Exit For
 Next
 
 set objWMI = Nothing
 
 OSVersion = intOSver
 
End Function
 
Function ConnectComputer(ByVal strUserName,  _
                         ByVal strPassword,  _
                         ByVal strServer,    _
    ByRef strNameSpace, _
                         ByRef objService)
 
    On Error Resume Next
 
    Dim objLocator, objWshNet
 
    ConnectComputer = False     'There is no error.
 
    'Create Locator object to connect to remote CIM object manager
 
    If IsEmpty (strUserName) Then
 Set objService = GetObject ("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strServer & "\" & strNameSpace)
        If Err.Number then
            Wscript.Echo "Error 0x" & Hex (Err.Number) & " occurred in acquiring a WMI object."
            If Err.Description <> "" Then
                Wscript.Echo "Error description: " & Err.Description & "."
            End If
            Err.Clear
            ConnectComputer = True     'An error occurred
 End If
        Exit Function
    End If
 
    Set objLocator = CreateObject ("WbemScripting.SWbemLocator")
    If Err.Number then
        Wscript.Echo "Error 0x" & Hex (Err.Number) & " occurred in creating a locator object."
        If Err.Description <> "" Then
            Wscript.Echo "Error description: " & Err.Description & "."
        End If
        Err.Clear
        ConnectComputer = True     'An error occurred
        Exit Function
    End If
 
    'Connect to the namespace which is either local or remote
    Set objService = objLocator.ConnectServer (strServer, strNameSpace, strUserName, strPassword)
    ObjService.Security_.impersonationlevel = 3
    If Err.Number then
        Wscript.Echo "Error 0x" & Hex (Err.Number) & _
                           " occurred in connecting to server " _
                           & strServer & "."
        If Err.Description <> "" Then
            Wscript.Echo "Error description: " & Err.Description & "."
        End If
        Err.Clear
        ConnectComputer = True     'An error occurred
    End If
 
End Function

Reply via email to