Need assistance on how to handle Object that doesn't get created or is nothing

On Line 105 of the code below, i.e. --> Set objService = objLocator.ConnectServer(strServer, "\root\default", strDomain & "\" & strUsername, strPassword), this object doesn't get created because I don't have access to that Server to pull the Registry data.
My problem is that when I add (Lines 73 - 84) the Is Nothing on my object in my If ElseIf statement, it pretty much thinks everything is not an object and ends up writing the error "Unable to make WMI Server connection; Error Number: -2147024891; Error Description: Access is denied.". I know this is not the case because when I don't add the "Is Nothing" in my If..ElseIf statement, it writes the Registry data to my output file. However, there is one Server that it hits and it just hangs there. So, I'm a little frustrated and could you some help to sift out the error in my code.
I do appreciate the help very much.
Thank you Experts,
Wallace
Option Explicit

On Error Resume Next

Const HKLM = &H80000002

Dim objExcel, objFSO, objInputFile, objService
Dim x, iRow, AnError
Dim strDomain, strUsername, strPassword
Dim strScriptPath, strServer, strServers, strFilePath, strNameAndVersion
Dim strKey, strSubKey1, strSavVer, strVersionCheck, strDName, strVName
Dim strSAV, strSAV0_N, strSAV0_V, strSAV1_N, strSAV1_V, strSAV2_N, strSAV2_V
Dim strSAV3_N, strSAV3_V, strSAV4_N, strSAV4_V, strSAV5_N, strSAV5_V
Dim strSAV6_N, strSAV6_V, strSAV7_N, strSAV7_V, strSAV8_N, strSAV8_V
Dim strSAV9_N, strSAV9_V, strSAV10_N, strSAV10_V, strSAV11_N, strSAV11_V

x = 2

'Create Excel Worksheet
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.Workbooks.Add

objExcel.Cells(1, 1).Value = "Server Name"
objExcel.Cells(1, 2).Value = "SAV Name"
objExcel.Cells(1, 3).Value = "SAV Version"
objExcel.Cells(1, 4).Value = "Errors?"

objExcel.Range("A1:E1").Select
objExcel.Selection.Interior.ColorIndex = 19
objExcel.Selection.Font.ColorIndex = 11
objExcel.Selection.Font.Bold = True
objExcel.Cells.EntireColumn.AutoFit

'Read in Server names from file
Set objFSO = CreateObject("Scripting.FileSystemObject")
strScriptPath = objFSO.GetParentFolderName(WScript.ScriptFullName)
strServers = WScript.Arguments.Item(0)
strFilePath = strScriptPath & "\" & strServers

Set objInputFile = objFSO.OpenTextFile(strFilePath, 1)

If IsEmpty(strServers)Then
	WScript.Echo "###########################################################"
	WScript.Echo "#     Usage: Detect_SavCE_Version.vbs ServerList.txt      #"
	WScript.Echo "#                                                         #"
	WScript.Echo "#     Important: You need to run this VBScript and        #"
	WScript.Echo "#                your serverlist.txt file from the        #"
	WScript.Echo "#                the same Directory path.                 #"
	WScript.Echo "#                                                         #"
	WScript.Echo "###########################################################"
	WScript.Quit
End If

strDomain = InputBox("Please enter your Domain name: ")
strUsername = InputBox("Please enter your Username: ")
strPassword = InputBox("Please enter your Password: ")

Do While Not (objInputFile.AtEndOfLine)
	strServer = ""
	strServer = objInputFile.ReadLine
	
	'Check if Server is available
	If Ping(strServer) = True Then
		iRow = x
		
		objExcel.Cells(iRow, 1).Value = strServer
		'Retrieve SavCE Version
		GetSavInfo
		
		AnError = "Error Number: " & Err.Number
		WScript.Echo AnError
		If Err.Number <> 0 Or Err.Number = 80070005 Then
			objExcel.Cells(iRow, 2).Value = "N/A"
			objExcel.Cells(iRow, 3).Value = "N/A"
			objExcel.Cells(iRow, 4).Value = "Unable to make WMI Server connection; " & "Error Number: " & _
											  Err.Number & "; " & "Error Description: " & Err.Description & "."
		ElseIf (objService) Is Nothing Then
			objExcel.Cells(iRow, 2).Value = "N/A"
			objExcel.Cells(iRow, 3).Value = "N/A"
			objExcel.Cells(iRow, 4).Value = "Unable to create object to make WMI Server connection; " & "Error Number: " & _
											  Err.Number & "; " & "Error Description: " & Err.Description & "."
			Err.Clear			
		End If

		x = x + 1
	Else
		iRow = x
		objExcel.Cells(iRow, 1).Value = strServer
		objExcel.Cells(iRow, 2).Value = "N/A"
		objExcel.Cells(iRow, 3).Value = "N/A"
		objExcel.Cells(iRow, 4).Value = "Ping Failed"
		x = x + 1
	End If
Loop

objExcel.Quit()

MsgBox "Done!"

Sub GetSavInfo
	Dim objRegistry, objLocator
	
	Set objLocator = CreateObject("WbemScripting.SWbemLocator")
	Set objService = objLocator.ConnectServer(strServer, "\root\default", strDomain & "\" & strUsername, strPassword)
	AnError = "Error Number: " & Err.Number
	WScript.Echo AnError
	objService.Security_.ImpersonationLevel = 3
	objService.Security_.AuthenticationLevel = 6
	Set objRegistry = objService.Get("StdRegProv")
'	Set objRegistry = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & _
'			strServer & "\root\default:StdRegProv")
	
	If Not(objRegistry) Is Nothing Then
	AnError = "Error Number: " & Err.Number
	WScript.Echo AnError
		'Check for SAV 10.1.6010.6
		strSAV = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{50E125D1-88E5-48CE-80AE-98EC9698E639}"
		objRegistry.GetStringValue HKLM, strSAV, "DisplayName", strSAV0_N
		objRegistry.GetStringValue HKLM, strSAV, "DisplayVersion", strSAV0_V
		
		'Check for SAV 10.1.5000.5
		strSAV = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{78D891EF-9E2D-4FC8-A71F-E6F897BA1B21}"
		objRegistry.GetStringValue HKLM, strSAV, "DisplayName", strSAV1_N
		objRegistry.GetStringValue HKLM, strSAV, "DisplayVersion", strSAV1_V
		
		'Check for SAV 10.1.4000.4
		strSAV = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{46B63F23-2B4A-4525-A827-688026BE5E40}"
		objRegistry.GetStringValue HKLM, strSAV, "DisplayName", strSAV2_N
		objRegistry.GetStringValue HKLM, strSAV, "DisplayVersion", strSAV2_V
		
		'Check for SAV 10.1.394.0
		strSAV = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{A011A1DC-7F1D-4EA8-BD11-0C5F9718E428}"
		objRegistry.GetStringValue HKLM, strSAV, "DisplayName", strSAV3_N
		objRegistry.GetStringValue HKLM, strSAV, "DisplayVersion", strSAV3_V
		
		'Version Unknown but will verify - 
		strSAV = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{BA4B71D1-898E-4306-AE87-8BA7A596F0ED}"
		objRegistry.GetStringValue HKLM, strSAV, "DisplayName", strSAV4_N
		objRegistry.GetStringValue HKLM, strSAV, "DisplayVersion", strSAV4_V
		
		'Version Unknown but will verify -
		strSAV = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{5A633ED0-E5D7-4D65-AB8D-53ED43510284}"
		objRegistry.GetStringValue HKLM, strSAV, "DisplayName", strSAV5_N
		objRegistry.GetStringValue HKLM, strSAV, "DisplayVersion", strSAV5_V	
		
		'Version Unknown but will verify -
		strSAV = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{473AF7D0-B864-4699-9974-DF570C5B6DCE}"
		objRegistry.GetStringValue HKLM, strSAV, "DisplayName", strSAV6_N
		objRegistry.GetStringValue HKLM, strSAV, "DisplayVersion", strSAV6_V	
		
		'Version Unknown but will verify -
		strSAV = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{33CFCF98-F8D6-4549-B469-6F4295676D83}"
		objRegistry.GetStringValue HKLM, strSAV, "DisplayName", strSAV7_N
		objRegistry.GetStringValue HKLM, strSAV, "DisplayVersion", strSAV7_V
		
		'Version Unknown but will verify -
		strSAV = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{D75D48AF-E2D5-49EF-9571-EE7AFB6565B4}"
		objRegistry.GetStringValue HKLM, strSAV, "DisplayName", strSAV8_N
		objRegistry.GetStringValue HKLM, strSAV, "DisplayVersion", strSAV8_V
		
		'Version Unknown but will verify -
		strSAV = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{0698CECB-9072-47B1-AEA1-94CA350989B8}"
		objRegistry.GetStringValue HKLM, strSAV, "DisplayName", strSAV9_N
		objRegistry.GetStringValue HKLM, strSAV, "DisplayVersion", strSAV9_V
		
		'Version Unknown but will verify -
		strSAV = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{E9FA3047-0b15-4e19-85ce-ee7fc6e60f99}"
		objRegistry.GetStringValue HKLM, strSAV, "DisplayName", strSAV10_N
		objRegistry.GetStringValue HKLM, strSAV, "DisplayVersion", strSAV10_V
		
		If Not IsNull(strSAV0_N) Or Not IsNull (strSAV0_V) Then
			objExcel.Cells(iRow, 2).Value = strSAV0_N
			objExcel.Cells(iRow, 3).Value = strSAV0_V
			objExcel.Cells(iRow, 4).Value = "N/A"
			strSAV0_N = Null
			strSAV0_V = Null
		ElseIf Not IsNull(strSAV1_N) Or Not IsNull (strSAV1_V) Then
			objExcel.Cells(iRow, 2).Value = strSAV1_N
			objExcel.Cells(iRow, 3).Value = strSAV1_V
			objExcel.Cells(iRow, 4).Value = "N/A"
			strSAV1_N = Null
			strSAV1_V = Null
		ElseIf Not IsNull(strSAV2_N) Or Not IsNull (strSAV2_V) Then
			objExcel.Cells(iRow, 2).Value = strSAV2_N
			objExcel.Cells(iRow, 3).Value = strSAV2_V
			objExcel.Cells(iRow, 4).Value = "N/A"
			strSAV2_N = Null
			strSAV2_V = Null
		ElseIf Not IsNull(strSAV3_N) Or Not IsNull (strSAV3_V) Then 
			objExcel.Cells(iRow, 2).Value = strSAV3_N
			objExcel.Cells(iRow, 3).Value = strSAV3_V
			objExcel.Cells(iRow, 4).Value = "N/A"
			strSAV3_N = Null
			strSAV3_V = Null
		ElseIf Not IsNull(strSAV4_N) Or Not IsNull (strSAV4_V) Then 
			objExcel.Cells(iRow, 2).Value = strSAV4_N
			objExcel.Cells(iRow, 3).Value = strSAV4_V
			objExcel.Cells(iRow, 4).Value = "N/A"
			strSAV4_N = Null
			strSAV4_V = Null
		ElseIf Not IsNull(strSAV5_N) Or Not IsNull (strSAV5_V) Then 
			objExcel.Cells(iRow, 2).Value = strSAV5_N
			objExcel.Cells(iRow, 3).Value = strSAV5_V
			objExcel.Cells(iRow, 4).Value = "N/A"
			strSAV5_N = Null
			strSAV5_V = Null
		ElseIf Not IsNull(strSAV6_N) Or Not IsNull (strSAV6_V) Then 
			objExcel.Cells(iRow, 2).Value = strSAV6_N
			objExcel.Cells(iRow, 3).Value = strSAV6_V
			objExcel.Cells(iRow, 4).Value = "N/A"
			strSAV6_N = Null
			strSAV6_V = Null
		ElseIf Not IsNull(strSAV7_N) Or Not IsNull (strSAV7_V) Then 
			objExcel.Cells(iRow, 2).Value = strSAV7_N
			objExcel.Cells(iRow, 3).Value = strSAV7_V
			objExcel.Cells(iRow, 4).Value = "N/A"
			strSAV7_N = Null
			strSAV7_V = Null
		ElseIf Not IsNull(strSAV8_N) Or Not IsNull (strSAV8_V) Then 
			objExcel.Cells(iRow, 2).Value = strSAV8_N
			objExcel.Cells(iRow, 3).Value = strSAV8_V
			objExcel.Cells(iRow, 4).Value = "N/A"
			strSAV8_N = Null
			strSAV8_V = Null
		ElseIf Not IsNull(strSAV9_N) Or Not IsNull (strSAV9_V) Then 
			objExcel.Cells(iRow, 2).Value = strSAV9_N
			objExcel.Cells(iRow, 3).Value = strSAV9_V
			objExcel.Cells(iRow, 4).Value = "N/A"
			strSAV9_N = Null
			strSAV9_V = Null
		ElseIf Not IsNull(strSAV10_N) Or Not IsNull (strSAV10_V) Then 
			objExcel.Cells(iRow, 2).Value = strSAV10_N
			objExcel.Cells(iRow, 3).Value = strSAV10_V
			objExcel.Cells(iRow, 4).Value = "N/A"
			strSAV10_N = Null
			strSAV10_V = Null
		Else
			objExcel.Cells(iRow, 2).Value = "SAV CE Name Unknown"
			objExcel.Cells(iRow, 3).Value = "SAV CE Version Unknown"
			objExcel.Cells(iRow, 4).Value = "N/A"
		End If
	End If

	Set objLocator = Nothing
	Set objService = Nothing
	Set objRegistry = Nothing

End Sub

'Ping Results
Function Ping(strServer)
	Dim objShell, boolResults
	Set objShell = CreateObject("WScript.Shell")
	boolResults = objShell.Run("Ping -n 2 -w 1000 " & strServer, 0, True)
	
	If boolResults = 0 Then
		Ping = True
	Else
		Ping = False
	End If
	
	Set objShell = Nothing
End Function

Open in new window

wally_davisAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

wally_davisAuthor Commented:
I managed to get the error. It took around 15 - 20 minutes for one computer in my list to report this error back. I'm, like, WTH... --> "Unable to make WMI Server connection; Error Number: -2147023174; Error Description: The RPC server is unavailable."
0
RobSampsonCommented:
Wally, this looks like it's most likely a WMI problem on the remote server.  Unfortunately, there's no connection time-out property you can set when the connection is being attempted, so all you can do is wait.  You can't even add more code, because that doesn't get executed until the GetObject call returns execution to the script.

I suggest that you need to look at the WMI Diagnostic tool on that particular server, and in the meantime, omit it from your results.

If you *really* wanted to put some form of time out, you could have the GetObject call execute in a second script, which the first would monitor for a certain time. If the execution returned to the first script within a certain time, then continue, otherwise report the error.  The downside of this approach would be that you execute two GetObject calls per machine...

Regards,

Rob.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
wally_davisAuthor Commented:
I suspected just as well Rob and thank you for confirming just that. I exhausted ever possibility with using the Err object and the Functions IsObject, Is Null, Is Empty, Is Nothing and Is Nothing worked best with respect to catching the Object that never got created in the first place. I have used the WMI Diagnostic and that's actually a really nice tool. It helped me once before so I'll run that just to see what issues I can find. I could write a second script and it would be kind of nice but since I'm not allowed to make changes to the Production boxes I can go to the upper echalant of Engineers and make that suggestion to them.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.