troubleshooting Question

MsgBox that shows computer not found instead of Nast VB system.exception window

Avatar of solomonacquah
solomonacquahFlag for United States of America asked on
Visual Basic.NET
2 Comments1 Solution290 ViewsLast Modified:
I have code here to kill a process on a remote machine.  If I put in a node name that doesn't exist, it throws a nast vb system.execption error, how can I make so that a simple Msgbox shows that just simply says computer not found or destination host cannot be contacted, or even access denied if the program is being run without the proper permissions.

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim objWMIService, objProcess, colProcess, objProgram
        Dim strComputer, strProcessKill, strInput, strexe, strShell

        strProcessKill = "''"

        If (Trim(Me.Pcname.Text) = "") Then
            Call MsgBox("Please, Type a Host Name or IP.", MsgBoxStyle.Exclamation, Application.ProductName)
            Exit Sub
        End If

        ' Input Box to get name of machine to run the process
            strComputer = Pcname.Text
            If strComputer <> "" Then
                strInput = True
            End If
        Loop Until strInput = True

        objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" _
        & strComputer & "\root\cimv2")

        colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = " & strProcessKill)
        For Each objProcess In colProcess
        TextBox1.Text = (" Just killed process " & strProcessKill _
        & " on " & strComputer)

    End Sub
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros