Closing another application

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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
 
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.
 
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.
 
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?
 
Back
Top