Closing an application

I need to close an application, Microsoft Outlook in particular.

How do I do it in VB 2005 Express

Thanks,

Antonio



Answer this question

Closing an application

  • Sheynema

    I apologize for this. You know ... something has changed over time. There is a standard snippet for this and it wouldn't work with Outlook.

    At any rate... here it is.....

    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.Kill()

    End If

    Next



  • Ys

    Using the code above I get:

    Value of type '1-dimensional array of System.Diagnostics.Process' cannot be converted to 'System.Diagnostics.Process'.

    I have tried

    Dim proc() As Process = Process.GetProcessesByName("outlook.exe")

    which does not have errors but I cannot write

    proc.kill

    I have tried proc().kill() but it gives error Number of indices is less than the number of dimensions of the indexed array.

    I have also tried

    Call Kill("C:\Program Files\Internet Explorer\IEXPLORE.EXE")

    I get

    Access to the path 'C:\Program Files\Internet Explorer\iexplore.exe' is denied.


  • GMehta

    Hi ReneeC,

    That did it!

    Most grateful.

    A bit sad though, I would have never done it on my own, the proc.id >4 is a difficult one.

    Again, many thanks,

    Antonio


  • questaware

    Great, great, thank you very much. I tried close, terminate and other synonims in the help but not kill...
  • Nathan Wiegman

    Sorry to post again. I have not received any replies or found anything on my own, may be someone knows this time...

    I believe that

    System.MarshalByRefObject()

    might be helpful, but I could not make it work.

    Any ideas

    Thanks,

    Antonio


  • Jmelgaard

    Dim proc As Process = Process.GetProcessesByName("OUTLOOK.EXE")

    Proc.KIll



  • Closing an application