strDomain = "bar.net"
strRecord = "foo.bar.net"
strGetIP = "http://myip.dnsdynamic.org/"
strLogFile = "C:\DynDNS.log"
'Getting external IP
Set oHTML = CreateObject("MSXML2.XMLhttp")
oHTML.Open "GET", strGetIP, False
oHTML.Send
strIPAddress = oHTML.ResponseText
Set oHTML = Nothing
' Connect to the WMI Service
Set objWMIService = GetObject("winmgmts:\\.\root\MicrosoftDNS")
' Run a query to get the record we want to change
Set colItems = objWMIService.ExecQuery("SELECT * FROM MicrosoftDNS_AType" & _
" WHERE ContainerName='" & strDomain & "' AND OwnerName='" & strRecord & "'",,48)
For Each objItem in colItems
' Modify the record if needed
If(objItem.IPAddress <> strIPAddress) Then
Wscript.Echo "IP Changed from " & objItem.IPAddress & " to " & strIPAddress
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(strLogFile, 8, true)
f.write("IP Changed from " & objItem.IPAddress & " to " & strIPAddress & vbCrLf)
objItem.Modify vbNull, strIPAddress
End if
Next