Question Kill a remote process

konradwalsh

New member
Joined
Oct 25, 2012
Messages
3
Programming Experience
1-3
Hi
I have searched and search for this answer but everything I try errors out.

I am trying to use WMI to check a Remote/Local network pc if a process is running. If it is, I want to kill the process.

Situation is that we have software that is used in the company called Alliance. We have 10 seats rolling seats. However only 2/3 people need to be in there all day. The problem is when the others use it, they use it for 5 minutes and then leave it open thus blocking others from using it. Then IT gets a call to say they cant get in.

I built a form that the user types in the offending pc name and clicks a check button. It checks if its running on the remote machine and returns an answer. This works 100%.

I then have a button made visible to kill the offending process but i cannot get that part to work.

I would appreciate any direction.

Here is my code so far:

VB.NET:
Public Class AllianceCtrl
    Dim strProcess As String
    Dim myP As System.Diagnostics.Process


    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnCheck.Click


        Dim strAllianceState As String = ""
        Dim strComputer As String = txtPCNAME.Text.ToUpper






        Do
            strProcess = "ALLIANCEMFG.EXE"


        Loop Until strProcess <> ""




        Do
        Loop Until strComputer <> ""


        myP() = Process.GetProcessesByName(strProcess)
        If (IsProcessRunning(strComputer, strProcess) = True) Then
            myP.Kill()
            strAllianceState = "Alliance is running on " & ControlChars.NewLine & strComputer
            lblAllianceStatus.Text = strAllianceState
            lblAllianceStatus.ForeColor = Color.Red
            btnCloseAlliance.Visible = True
            btnCloseAlliance.Text = "Close Alliance On " & ControlChars.NewLine & strComputer






        Else


            strAllianceState = " Alliance is not running on " & ControlChars.NewLine & strComputer
            lblAllianceStatus.Text = strAllianceState
            lblAllianceStatus.ForeColor = Color.Green
            btnCloseAlliance.Visible = False


        End If


    End Sub
 


  


    Private Sub btnCloseAlliance_Click(sender As Object, e As EventArgs) Handles btnCloseAlliance.Click
       
        myP.Kill()


        myP.CloseMainWindow()


        'If myP.ProcessName = Me.strProcess Then


        '    myP.Kill()


        'End If




    End Sub










    Function IsProcessRunning(ByVal strServer, ByVal strProcess)
        Dim Process, strObject
        IsProcessRunning = False
        strObject = "winmgmts://" & strServer
        For Each Process In GetObject(strObject).InstancesOf("win32_process")
            If UCase(Process.name) = UCase(strProcess) Then
                IsProcessRunning = True
                Exit Function
            End If
        Next
    End Function


    Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
        Me.Close()


    End Sub
End Class
 
Back
Top