[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now


check if machine exists in network?

Posted on 2004-10-23
Medium Priority
Last Modified: 2007-12-19
I have made a little applikation which checks some settings on a range of machien in the network. It works fine, but if a machine i unavailable(turned off or machien name is unvalid), then the appliaktion teminates with:

"The remote machine does not exist or is unavailble"....and then my applikation stop running.

I would like the applikation to proced to the next machine if a machine is not to be reached.

Can somebody help me??
The applikation is made in VB, but a vbs scritpt is also ok.
Question by:aslandk
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 12387882
Very hard to answer without seeing your code, but locate the line that causes the crash (probably the one that opens the remote connection) and add some error handling around it. Something like the following might do it:

On Error Goto NextComputer
  ' Check settings here


On Error Goto 0
' Loop or whatever you do to check the next computer.

Author Comment

ID: 12387923
The error occures in this linie:
Set UserSet = GetObject("winmgmts:{impersonationLevel=impersonate}!//" & computername & "").InstancesOf("Win32_ComputerSystem")

What is the best to catch that kind of error? Is it "just" On Error Goto ....?
LVL 20

Expert Comment

ID: 12388124
Declare this:

Private Type QOCINFO
    dwSize As Long
    dwFlags As Long
    dwInSpeed As Long 'in bytes/second
    dwOutSpeed As Long 'in bytes/second
End Type
Private Declare Function IsDestinationReachable Lib "SENSAPI.DLL" Alias "IsDestinationReachableA" (ByVal lpszDestination As String, ByRef lpQOCInfo As QOCINFO) As Long

' Then in your Sub/Function declare
  Ret.dwSize = Len(Ret)

'Then before your Set UserSet
  ' Perform a loop here changing computername as you do now
  If IsDestinationReachable(computername, Ret) = 0 Then
      ' Your Code Here
      ' Log Error Here or just ignore
  End If
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Expert Comment

ID: 12388128
You havn't another way to catch this error, you can ony handle it and proceed to the next machine

On Error GoTo Error_Handle

'Your Loop

Set UserSet = GetObject("winmgmts:{impersonationLevel=impersonate}!//" & computername & "").InstancesOf("Win32_ComputerSystem")

'End Your Loop

    Select Case Err.Number
       Case 462:
       'Here you can handle "The remote machine does not exist or is unavailble"
       'and return to you loop
       'Other errors will not be handled
       Debug.Print Err.Description
       Resume Next
    End Select
LVL 20

Expert Comment

ID: 12388202
Whoops mistyped Change
  If IsDestinationReachable(computername, Ret) = 0 Then
      ' Your Code Here
      ' Log Error Here or just ignore
  End If


  If IsDestinationReachable(computername, Ret) = 0 Then
      ' Log Error Here or just ignore
      ' Your code here
  End If

Expert Comment

ID: 12388291
VB isn't packed with sophisticated error handling methods, so On Error Goto is pretty much your only way. The "IsDestinationReachable" approach is works too, but causes an unnecessary connection being opened - and you need to check for errors anyway if you want your code to be really robust (getting the information can fail in other ways too).

Expert Comment

ID: 12388381
Do you know what port you are using to connect to the pc?
If you do, you can use a winsock control to see if the pc is there

    Winsock1.RemoteHost = theIpAddress
    Winsock1.RemotePort = thePortNumber

'have connected
Private Sub Winsock1_Connect()
  'continue your code
End Sub

'Not connected
Private Sub Winsock1_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
   'goto the next computer
End Sub

Expert Comment

ID: 12388905
On Error statements in Visual Basic are available and can be utilized and called in a variety of methods to suit your needs. The methods implemented derive from `C` programming, and have been adapted into the Visual Basic syntax.

' Suppress Error notification with Visual Basic.
On Error Resume Next

Other available methods are also easily implemented in much the same way, these being.

-: On Error GoTo 0
-: On Error Resume Next
-: On Error GoTo line

A standard practice when tracing errors in applications is to implement a basic routine which catches and displays return code values for each routine independently.

‘ Define reference to our error handler
On Error GoTo err_handler:

‘ Code functions within subroutine go here:

‘ We expect 1object numeric and1object as text
  txtOutput.Text = "Error " & Err.Number & ": " & Err.Description

End Sub

We can elaborate on this method and build up a stack with variation in formatting as demonstrated:

On Error GoTo Error1
    Exit Sub

    On Error GoTo Error2
    MsgBox "Error1:" & Str$(Err.Number) & "." & vbCrLf & _
    Resume Next

    MsgBox "Error2:" & Str$(Err.Number) & "." & vbCrLf & _
    Resume Next

We can use a bespoke handler in our application as errors generate, as we know what to expect from each error and can determine how to handle each independently. Illustrated in the case of your routine not being available to demonstrate how you are utilizing Active-X components within your application or if you are making native systems calls with VB or VB Script, I have chose to illustrate with a precompiled Active-X component.

Visual Basic developers have an array of 3rd party Active-X components and `dynamic linked libraries` - DLL extensions which makes for rapid application development and cuts development to the work of building custom GUI’s in VB or C#. As a result these components are common purchases in SME environments.

When redistribution and commercial deployment of the application is a real consideration, it is recommended investing in creating your own DLL to provide the `Network Layer` and API required for your VB front end.
Some of the unique or distinctive products, providing pre-defined methods for `out of the box` network programmings are:

Catalyst – Socket Tools - http://www.catalyst.com/
Component Space - .NET Internet component suite - http://www.componentspace.com/icmp.aspx
OstroSoft - ICMP Component - http://www.ostrosoft.com/ICMP_component.asp

We need a routine which sweeps an IP range belonging to a specific subnet. For the purpose of this routine I have chosen to use the TCP command ICMP_NETECHO which is provided by the OstroSoft `ICMP Component` which I have downloaded and unzipped the “OSICMP.dll” from the archive to my system directory, and registered with the following command:

C:\WINDOWS>regsvr32 OSICMP.dll

When looking into the guide on and example code you can see an implementation of the error handling discussed previously and out of the box an example application is ready to compile and adapt to your needs with little effort.

Happy Programming!
LVL 20

Expert Comment

ID: 12631008
  aslandk has not left the building just this question,(s)he just asked another new question yesterday in VB. There are a couple of workable solutions posted, at the least PAQ no refund.

Accepted Solution

modulo earned 0 total points
ID: 12654101
PAQed with no points refunded (of 500)

Community Support Moderator

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Simple Linear Regression
Starting up a Project

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question