Home All Groups Group Topic Archive Search About

Closing another application

Author
26 May 2006 8:57 AM
Helen Trim
I have scheduled programs that run overnight.  One of them leaves a window
open and this stops other users opening the program.  It is a third-party
application.

Can I write a vb .NET program to add to the schedule to close it?  What
object can be used to reference another application?

TIA
--
Helen

Author
26 May 2006 9:22 AM
arthurjr07
Try this

Private Sub KillExcel()

        Dim myProcesses As Process
        Dim myProcess As Process

        myProcesses = Process.GetProcessesByName("EXCEL.EXE")
        For Each myProcess In myProcesses
            myProcess.Kill()
        Next

        myProcesses = Nothing
        myProcess = Nothing

    End Sub

HTH
Author
26 May 2006 9:45 AM
Helen Trim
That's exactly what I need.  I have tried it and it works.

Thanks.
--
Helen


Show quoteHide quote
"arthurj***@gmail.com" wrote:

> Try this
>
> Private Sub KillExcel()
>
>         Dim myProcesses As Process
>         Dim myProcess As Process
>
>         myProcesses = Process.GetProcessesByName("EXCEL.EXE")
>         For Each myProcess In myProcesses
>             myProcess.Kill()
>         Next
>
>         myProcesses = Nothing
>         myProcess = Nothing
>
>     End Sub
>
> HTH
>
>
Author
26 May 2006 11:37 AM
Herfried K. Wagner [MVP]
<arthurj***@gmail.com> schrieb:
> Private Sub KillExcel()
>
>        Dim myProcesses As Process
>        Dim myProcess As Process
>
>        myProcesses = Process.GetProcessesByName("EXCEL.EXE")
>        For Each myProcess In myProcesses
>            myProcess.Kill()

Maybe it's better to use 'MyProcess.CloseMainWindow()' instead of calling
the 'Kill' method.

>        myProcesses = Nothing
>        myProcess = Nothing

Setting the variables to 'Nothing' here doesn't make sense and doesn't need
to be done as it's done automatically when the method is left.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
1 Jun 2006 5:52 PM
cj
Herfried,

I'm thinking of using this process too.  If I use
MyProcess.CloseMainWindow will the command wait for the other programs
to end before it returns or will it just issue a command to them to
close then move on to the next program?

Here's why, I'm looking to reboot the pc at 2am each day (you might have
read some of my questions on rebooting via program) and would like write
a program to do this but I want it to shutdown any other programs that
might be running before rebooting the pc.


Herfried K. Wagner [MVP] wrote:
Show quoteHide quote
> <arthurj***@gmail.com> schrieb:
>> Private Sub KillExcel()
>>
>>        Dim myProcesses As Process
>>        Dim myProcess As Process
>>
>>        myProcesses = Process.GetProcessesByName("EXCEL.EXE")
>>        For Each myProcess In myProcesses
>>            myProcess.Kill()
>
> Maybe it's better to use 'MyProcess.CloseMainWindow()' instead of
> calling the 'Kill' method.
>
>>        myProcesses = Nothing
>>        myProcess = Nothing
>
> Setting the variables to 'Nothing' here doesn't make sense and doesn't
> need to be done as it's done automatically when the method is left.
>
Author
1 Jun 2006 7:22 PM
cj
I can get it to kill all processes just as I can list them below

         Dim myprocesses() As Process
         Dim myprocess As Process

         myprocesses = Process.GetProcesses
         For Each myprocess In myprocesses
             Debug.WriteLine(myprocess.ProcessName)
         Next

but the problem is I wouldn't want to kill all the processes.  That
would be a problem.  I want to exit all "applications" currently running.

Then again the whole idea probably will not work as many of the apps
written are home grown and probably would either not respond to a
shutdown request or would close abruptly w/o finishing up what they are
doing.  And MS apps don't even need closing as the act of shutting down
windows causes them to shut down.  How do they know windows is closing?


cj wrote:
Show quoteHide quote
> Herfried,
>
> I'm thinking of using this process too.  If I use
> MyProcess.CloseMainWindow will the command wait for the other programs
> to end before it returns or will it just issue a command to them to
> close then move on to the next program?
>
> Here's why, I'm looking to reboot the pc at 2am each day (you might have
> read some of my questions on rebooting via program) and would like write
> a program to do this but I want it to shutdown any other programs that
> might be running before rebooting the pc.
>
>
> Herfried K. Wagner [MVP] wrote:
>> <arthurj***@gmail.com> schrieb:
>>> Private Sub KillExcel()
>>>
>>>        Dim myProcesses As Process
>>>        Dim myProcess As Process
>>>
>>>        myProcesses = Process.GetProcessesByName("EXCEL.EXE")
>>>        For Each myProcess In myProcesses
>>>            myProcess.Kill()
>>
>> Maybe it's better to use 'MyProcess.CloseMainWindow()' instead of
>> calling the 'Kill' method.
>>
>>>        myProcesses = Nothing
>>>        myProcess = Nothing
>>
>> Setting the variables to 'Nothing' here doesn't make sense and doesn't
>> need to be done as it's done automatically when the method is left.
>>