I am trying to add a simple error handeling check in my script but doesn't seem to be working.
The script will work fine with servers that exist and don't cause error contitions but ones that would cause an error it doesn't seem to work.
Basicly I am testing to connect to a server that doesn't exist, which would cause an error condition. So I added some msgbox statements to track it and the server name passes fine and then connects to wmi but the next statement doesn't happen I never see the err.number result and the condition test never happens either. It just seems like it just exits the function.
Can someone point me in the correct direction? Thanks
The script will work fine with servers that exist and don't cause error contitions but ones that would cause an error it doesn't seem to work.
Basicly I am testing to connect to a server that doesn't exist, which would cause an error condition. So I added some msgbox statements to track it and the server name passes fine and then connects to wmi but the next statement doesn't happen I never see the err.number result and the condition test never happens either. It just seems like it just exits the function.
Can someone point me in the correct direction? Thanks
Code:
On Error Resume Next
ShowDnsWins("testnoserver")
Sub ShowDnsWins( strServer )
MsgBox strServer
Set objNICs = GetObject("winmgmts:{impersonationLevel=impersonate}!//"& strServer)
MsgBox Err.Number
If Err.Number <> 0 Then
MsgBox "Here:" & Err.Number
strLine = strServer & "," & Err.Description
Err.Clear
objReport.WriteLine (strLine)
Else
Set colNICs = objNICs.InstancesOf( "Win32_NetworkAdapterConfiguration" )
strLine = strServer & ","
For Each NIC In colNICs
If NIC.IPEnabled Then
strLine = strLine & NIC.Description & ","
n = 1
For Each strDns In NIC.DNSServerSearchOrder
strLine = strLine & strDns & ","
n = n + 1
Next
n=1
strLine = strLine & NIC.WINSPrimaryServer & ","
strLine = strLine & NIC.WINSSecondaryServer
End If
Next
objReport.WriteLine (strLine)
End If
End Sub