nonsparker
Technical User
thread329-898604
I was using the script in the thread above and I keep getting a remote procedure call failed error and I was wondering if the reason was that I am calling the same function 2 times in a script. Below is my script. I only get the error when the script calls the function the second time .
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
stage = 1
REM Check to see if the Wireless adapter is connected
Do
Set colItems = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapter Where Name = 'VIA Networking Technologies USB Wireless LAN Adapter'")
For Each objItem in colItems
Select Case objItem.NetConnectionStatus
Case 0 strStatus = "Disconnected"
Case 1 strStatus = "Connecting"
Case 2 strStatus = "Connected"
Case 3 strStatus = "Disconnecting"
Case 4 strStatus = "Hardware not present"
Case 5 strStatus = "Hardware disabled"
Case 6 strStatus = "Hardware malfunction"
Case 7 strStatus = "Media disconnected"
Set colItems2 = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapter Where Name = 'VIA Rhine II Fast Ethernet Adapter'")
For Each objItem2 in colItems2
Select Case objItem2.NetConnectionStatus
Case 0 strStatus2 = "Disconnected"
Case 1 strStatus2 = "Connecting"
Case 2 strStatus2 = "Connected"
strStatus = "Connected"
Case 3 strStatus2 = "Disconnecting"
Case 4 strStatus2 = "Hardware not present"
Case 5 strStatus2 = "Hardware disabled"
Case 6 strStatus2 = "Hardware malfunction"
Case 7 strStatus2 = "Media disconnected"
Wscript.Echo "Your ethernet cable is not plugged in and your Wireless is turned off." & vbCrLf & "Please Plug in the wire or turn on the wireless switch." & vbCrLf & "For more help please call the help desk ext. 4357"
Case 8 strStatus2 = "Authenticating"
Case 9 strStatus2 = "Authentication succeeded"
Case 10 strStatus2 = "Authentication failed"
Case 11 strStatus2 = "Invalid address"
Case 12 strStatus2 = "Credentials required"
End Select
Next
Case 8 strStatus = "Authenticating"
Case 9 strStatus = "Authentication succeeded"
Case 10 strStatus = "Authentication failed"
Case 11 strStatus = "Invalid address"
Case 12 strStatus = "Credentials required"
End Select
Wscript.Echo "strStatus:" & strStatus
Wscript.Echo "strStatus2:" & strStatus2
If stage > 0 Then
stage = DisplayProgress(stage)
End If
Next
Loop Until strStatus="Connected"
stage = 1
REM Check to see if the client can ping the Connection Broker
Do
If stage > 0 Then
stage2 = DisplayProgress(stage)
End If
REM Wscript.Echo "Ping Fail!"
Loop While IsAlive("view45con.rps.ad")="False"
REM Set the shell to the View client
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "C:\etc\View_45_secondary.cmd" & Chr(34), 0
Set WshShell = Nothing
Function IsAlive(strHost)
'---------- Test to see if host or url alive through ping -----------------
' Returns True if Host responds to ping
'
' Though there are other ways to ping a computer, Win2K,
' XP and different versions of PING return different error
' codes. So the only reliable way to see if the ping
' was sucessful is to read the output of the ping
' command and look for "TTL="
'
' strHost is a hostname or IP
Const OpenAsASCII = 0
Const FailIfNotExist = 0
Const ForReading = 1
Dim objShell, objFSO, sTempFile, fFile
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
sTempFile = objFSO.GetSpecialFolder(2).ShortPath & "\" & objFSO.GetTempName
objShell.Run "%comspec% /c ping.exe -n 2 -w 500 " & strHost & ">" & sTempFile, 0 , True
Set fFile = objFSO.OpenTextFile(sTempFile, ForReading, FailIfNotExist, OpenAsASCII)
Select Case InStr(fFile.ReadAll, "TTL=")
Case 0
IsAlive = False
Case Else
IsAlive = True
End Select
fFile.Close
objFSO.DeleteFile(sTempFile)
Set objFSO = Nothing
Set objShell = Nothing
End Function
Function DisplayProgress(stage)
'Here is a phony progress bar that uses an IE Window
set x = CreateObject("InternetExplorer.Application")
'in code, the colon acts as a line feed
x.navigate2 "about:blank" : x.width = 350 : x.height = 80 : x.toolbar = false : x.menubar = false : x.statusbar = false : x.visible = True
x.document.write "<font color=blue>"
For n = 1 to 100
x.document.write "|"
wscript.sleep 100
x.document.title = "Connecting to network " & stage & " " & " " & n & " %"
Next
stage = stage + 1
'close the window
x.quit
set x = nothing
DisplayProgress = stage
End Function
I was using the script in the thread above and I keep getting a remote procedure call failed error and I was wondering if the reason was that I am calling the same function 2 times in a script. Below is my script. I only get the error when the script calls the function the second time .
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
stage = 1
REM Check to see if the Wireless adapter is connected
Do
Set colItems = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapter Where Name = 'VIA Networking Technologies USB Wireless LAN Adapter'")
For Each objItem in colItems
Select Case objItem.NetConnectionStatus
Case 0 strStatus = "Disconnected"
Case 1 strStatus = "Connecting"
Case 2 strStatus = "Connected"
Case 3 strStatus = "Disconnecting"
Case 4 strStatus = "Hardware not present"
Case 5 strStatus = "Hardware disabled"
Case 6 strStatus = "Hardware malfunction"
Case 7 strStatus = "Media disconnected"
Set colItems2 = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapter Where Name = 'VIA Rhine II Fast Ethernet Adapter'")
For Each objItem2 in colItems2
Select Case objItem2.NetConnectionStatus
Case 0 strStatus2 = "Disconnected"
Case 1 strStatus2 = "Connecting"
Case 2 strStatus2 = "Connected"
strStatus = "Connected"
Case 3 strStatus2 = "Disconnecting"
Case 4 strStatus2 = "Hardware not present"
Case 5 strStatus2 = "Hardware disabled"
Case 6 strStatus2 = "Hardware malfunction"
Case 7 strStatus2 = "Media disconnected"
Wscript.Echo "Your ethernet cable is not plugged in and your Wireless is turned off." & vbCrLf & "Please Plug in the wire or turn on the wireless switch." & vbCrLf & "For more help please call the help desk ext. 4357"
Case 8 strStatus2 = "Authenticating"
Case 9 strStatus2 = "Authentication succeeded"
Case 10 strStatus2 = "Authentication failed"
Case 11 strStatus2 = "Invalid address"
Case 12 strStatus2 = "Credentials required"
End Select
Next
Case 8 strStatus = "Authenticating"
Case 9 strStatus = "Authentication succeeded"
Case 10 strStatus = "Authentication failed"
Case 11 strStatus = "Invalid address"
Case 12 strStatus = "Credentials required"
End Select
Wscript.Echo "strStatus:" & strStatus
Wscript.Echo "strStatus2:" & strStatus2
If stage > 0 Then
stage = DisplayProgress(stage)
End If
Next
Loop Until strStatus="Connected"
stage = 1
REM Check to see if the client can ping the Connection Broker
Do
If stage > 0 Then
stage2 = DisplayProgress(stage)
End If
REM Wscript.Echo "Ping Fail!"
Loop While IsAlive("view45con.rps.ad")="False"
REM Set the shell to the View client
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "C:\etc\View_45_secondary.cmd" & Chr(34), 0
Set WshShell = Nothing
Function IsAlive(strHost)
'---------- Test to see if host or url alive through ping -----------------
' Returns True if Host responds to ping
'
' Though there are other ways to ping a computer, Win2K,
' XP and different versions of PING return different error
' codes. So the only reliable way to see if the ping
' was sucessful is to read the output of the ping
' command and look for "TTL="
'
' strHost is a hostname or IP
Const OpenAsASCII = 0
Const FailIfNotExist = 0
Const ForReading = 1
Dim objShell, objFSO, sTempFile, fFile
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
sTempFile = objFSO.GetSpecialFolder(2).ShortPath & "\" & objFSO.GetTempName
objShell.Run "%comspec% /c ping.exe -n 2 -w 500 " & strHost & ">" & sTempFile, 0 , True
Set fFile = objFSO.OpenTextFile(sTempFile, ForReading, FailIfNotExist, OpenAsASCII)
Select Case InStr(fFile.ReadAll, "TTL=")
Case 0
IsAlive = False
Case Else
IsAlive = True
End Select
fFile.Close
objFSO.DeleteFile(sTempFile)
Set objFSO = Nothing
Set objShell = Nothing
End Function
Function DisplayProgress(stage)
'Here is a phony progress bar that uses an IE Window
set x = CreateObject("InternetExplorer.Application")
'in code, the colon acts as a line feed
x.navigate2 "about:blank" : x.width = 350 : x.height = 80 : x.toolbar = false : x.menubar = false : x.statusbar = false : x.visible = True
x.document.write "<font color=blue>"
For n = 1 to 100
x.document.write "|"
wscript.sleep 100
x.document.title = "Connecting to network " & stage & " " & " " & n & " %"
Next
stage = stage + 1
'close the window
x.quit
set x = nothing
DisplayProgress = stage
End Function