Avatar of solomonacquah
solomonacquahFlag for United States of America

asked on 

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

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
        Do
            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
            objProcess.Terminate()
        Next
        TextBox1.Text = (" Just killed process " & strProcessKill _
        & " on " & strComputer)

    End Sub
Visual Basic.NET

Avatar of undefined
Last Comment
solomonacquah
ASKER CERTIFIED SOLUTION
Avatar of appari
appari
Flag of India image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of solomonacquah

ASKER

Thank You appari Works Perfectly.
Visual Basic.NET
Visual Basic.NET

Visual Basic .NET (VB.NET) is an object-oriented programming language implemented on the .NET framework, but also supported on other platforms such as Mono and Silverlight. Microsoft launched VB.NET as the successor to the Visual Basic language. Though it is similar in syntax to Visual Basic pre-2002, it is not the same technology,

96K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo