[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 528
  • Last Modified:

check if machine exists in network?

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
aslandk
Asked:
aslandk
1 Solution
 
der_jthCommented:
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
 
aslandkAuthor Commented:
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
 
hesCommented:
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
ariel_tCommented:
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
 
hesCommented:
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
 
der_jthCommented:
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
 
scanadminCommented:
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
 
mrhassellCommented:
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
 
hesCommented:
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
 
moduloCommented:
PAQed with no points refunded (of 500)

modulo
Community Support Moderator
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now