Solved

check if machine exists in network?

Posted on 2004-10-23
524 Views
Last Modified: 2007-12-19
Hello
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.
0
Question by:aslandk
    10 Comments
     
    LVL 6

    Expert Comment

    by:der_jth
    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

    NextComputer:

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

    Author Comment

    by:aslandk
    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 ....?
    0
     
    LVL 24

    Expert Comment

    by:hes
    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
    Dim Ret As QOCINFO
      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
      Else
          ' Log Error Here or just ignore
      End If
    0
     

    Expert Comment

    by:ariel_t
    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

    Error_Handle:
        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
    0
     
    LVL 24

    Expert Comment

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

    TO:

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

    Expert Comment

    by:der_jth
    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).
    0
     
    LVL 1

    Expert Comment

    by:scanadmin
    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.Close
        Winsock1.RemoteHost = theIpAddress
        Winsock1.RemotePort = thePortNumber
        Winsock1.Connect

    '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
    0
     

    Expert Comment

    by:mrhassell
    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
    err_handler:
      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
        Subroutine1
        Subroutine2
        Exit Sub

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

    Error2:
        MsgBox "Error2:" & Str$(Err.Number) & "." & vbCrLf & _
            Err.Description
        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!
    0
     
    LVL 24

    Expert Comment

    by:hes
    Venabili,
      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.
    0
     

    Accepted Solution

    by:
    PAQed with no points refunded (of 500)

    modulo
    Community Support Moderator
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Suggested Solutions

    Title # Comments Views Activity
    withoutTen challenge 14 50
    scoresAverage challenge 8 42
    sumDigits  challenge 7 22
    allStar challenge 1 12
    This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
    How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

    913 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

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now