|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Closing another applicationI 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 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 That's exactly what I need. I have tried it and it works.
Thanks. -- Show quoteHide quoteHelen "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 > > <arthurj***@gmail.com> schrieb:
> Private Sub KillExcel() Maybe it's better to use 'MyProcess.CloseMainWindow()' instead of calling > > Dim myProcesses As Process > Dim myProcess As Process > > myProcesses = Process.GetProcessesByName("EXCEL.EXE") > For Each myProcess In myProcesses > myProcess.Kill() the 'Kill' method. > myProcesses = Nothing Setting the variables to 'Nothing' here doesn't make sense and doesn't need > myProcess = Nothing 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/> 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. > 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. >>
converting the use of interfaces under vb6 to vb.net
WebBrowser Control Frame Documents How to translate C++ 'for' loop into VB.NET? error handle Windows Service using VB.Net automatic startup problem ! make a form shared - called from another form - how? ClickOnce deployment problem! Text color list box Stupid Question of the day...... opening a document with system's default app |
|||||||||||||||||||||||