Results 1 to 3 of 3

Thread: Kill a remote process

  1. #1
    konradwalsh is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Oct 2012
    Posts
    3
    Reputation
    0

    Post Kill a remote process

    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:

    Code:
    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

  2. #2
    konradwalsh is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Oct 2012
    Posts
    3
    Reputation
    0
    any body?

    there must be someone with this issue

  3. #3
    konradwalsh is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Oct 2012
    Posts
    3
    Reputation
    0
    ok.. so i figured it out...

    use pskill - PsKill

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •