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 ProviderOK, 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 = 2Const int2003PrimaryZone = 0
Const int2003SecondaryZone = 1
Const int2003StubZone = 2
Const int2003ForwardZone = 3'' code'
Sub CreateTheZone (objZoneRef, strZoneName)
' Create the Zone
Dim errResultWScript.Echo "Creating zone " & strZoneName
If intOS = 2000 Then
errResult = objZoneRef.CreateZone (strZoneName, int2000PrimaryZone)
Else
'intOS = 2003
errResult = objZoneRef.CreateZone (strZoneName, int2003PrimaryZone, False)
End IfWScript.Echo "Created zone " & strZoneName & ", will now create resource records"
End SubSub SaveTheZone (objWMI, strZoneName)
' Write the zone back to disk
Dim objZone, objZonesWScript.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 SubFunction OSVersion (strUser, strPass, strServer)
Dim colOS, objOS, strCaption, intOSver, objWMIintOSver = -1If ConnectComputer (strUser, strPass, strServer, "root\cimv2", objWMI) Then
Wscript.Echo "*** Error: Could not connect to CIMv2 namespace on " & strServer
WScript.Quit 1
End IfSet 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
Nextset objWMI = NothingOSVersion = intOSverEnd FunctionFunction ConnectComputer(ByVal strUserName, _
ByVal strPassword, _
ByVal strServer, _
ByRef strNameSpace, _
ByRef objService)On Error Resume NextDim objLocator, objWshNetConnectComputer = False 'There is no error.'Create Locator object to connect to remote CIM object managerIf 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 IfSet 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 IfEnd Function
