Stop remote process

I need to stop Outlook running on a remote computer in the network.

I know how to stop Outlook when it is running on the local system (code at the end)

I am aware that the help file for the Process class says "local" for start and stop:

"Provides access to local and remote processes and enables you to start and stop local system processes"

However, this is becoming for me a pressing need and there should be a solution.

Thanks,

Antonio

Dim processes() As Process = Process.GetProcesses

For Each proc As Process In processes

If proc.Id > 4 Then

If proc.MainModule.ModuleName = "OUTLOOK.EXE" Then proc.CloseMainWindow()

If proc.MainModule.ModuleName = "OUTLOOK.EXE" Then proc.Close()

End If

Next



Answer this question

Stop remote process

  • chinna145

    Hi James,

    Your info looks promising. I will take a closer look at it later.

    In the meantime, I have found out the following code that works in VBA, but does not close the application very cleanly:

    Option Explicit
    Sub main()


    Dim sComputer, sProcess, oShell
    Const WindowStyle = 0
    Const WaitOnReturn = True

    sComputer = "dell-650" ' remote machine
    sProcess = "outlook.exe" ' app on remote machine
    Set oShell = CreateObject("WScript.Shell")
    oShell.Run "TaskKill /s " & sComputer & " /im " & sProcess & " /f", WindowStyle, WaitOnReturn
    Set oShell = Nothing

    End Sub


  • jtan

    You might want to have a look at WMI, with this you are able to do almost every task, you just have to learn the language and such. With WMI you should be able to enumerate the processes running on the remote computer and then target and kill the one you want. The other bonus is that you can also code in the security system to allow this to be done by none admins... (But that is up to you).

    I have not seen many examples of WMI in .Net but in the past I have looked at the scripting centre on Technet and converted the code from VBScript. You just need to make sure that you ave the system.management assembly referenced in your application.



  • Flimflam

    Hi James,

    We both understand the security issues and the need for Admin rights and the like. Let us assume we have all that.

    Being able to kill a remote application is something very important.

    I have to do it using MS Remote Desktop, but it is not programmatically. So it is not good.

    If you tell me that Linux can kill a remote application I really hope Windows can do it too, because otherwise I would be very disappointed with MS.

    I am certainly not hopeful, I have already tried.

    Regards,

    Antonio


  • abcdefgqwerty2

    Of course you can do this with MicroSoft.

    I certainly support Trucker's approach. In a way, he's referring to a control server or service.

    There is another approach to it also:

    MSDN WMI

    WMI Reference



  • Topboy

    Hi Glenn,

    Thank you for your comments.

    I have been taking a look at WMI. It seems that it does require a somewhat steep learning curve for me.

    Since the VB code above does roughly work I think I will stick with it (...for now, I know myself)

    Regards,

    Antonio


  • antointhe

    Here is a C# example using Remoting that you may be able to convert to VB to do what you want:

    http://www.codeproject.com/csharp/stoppingremotingservice.asp

    Other than that, the Remote Desktop may be your only choice if you are not the Network Admin on your network.

    james

    aka:Trucker


  • martin_lofberg

    I would think that stopping a proccess on another computer on the network would require an application already on the other computer that could respond to a command from you over the network. I can see where there might be issues with permissions otherwise. I know on a Linux based network, you can telnet into another computer on the network and Kill an application or proccess. If you have Admin rights. I'm not sure with Windows if that is possible. It will be interesting to find out the answer to to this one.

    james

    aka:Trucker


  • Stop remote process