Re: Closing a program with script...



Using Process Explorer to see the PID, launching several instances of Word
only generates one PID. Have to repeat the close procedure until all are
closed. Launching several instances of IE behaves as you describe.

Taskkill looks more interesting, but it still requires that the script
identify apps that are open that need to be closed, as opposed to services,
etc., that you don't want killed.

I think EndItAll is probably the best solution.

--
Gary S. Terhune
MS-MVP Shell/User
www.grystmill.com

"Pegasus (MVP)" <I.can@xxxxxxx> wrote in message
news:%23a1wmXi4HHA.1168@xxxxxxxxxxxxxxxxxxxxxxx
If you have several applications of the same name then each
has its own PID. Switching to that PID and using Alt+F4
would kill each application individually.

A more effective method might be to use taskkill.exe (another
WinXP Professional tool):

taskkill /PID nnn /f
taskkill /Im Winword /f

The /f switch would take care of user prompts.


"Gary S. Terhune" <none> wrote in message
news:ePj4%23ze4HHA.2752@xxxxxxxxxxxxxxxxxxxxxxx
Never mind, it works. While SendKeys doesn't work well if the window
isn't actually brought up (AppActivate doesn't actually pull up the
window) the use of Alt-F4 works for any of them. But this other thing
would need to be dealt with: Say you have two instances of an app like
Word open. AppActivate only activates one of them, arbitrarily. The
remaining instance would have the same PID, so the script would need to
loop through the same PID until none was found to exist. The script
generates no errors using AppActivate if the PID doesn't exist. It just
skips on by. AppActivate supposedly returns a Boolean value, but damned
if I can retrieve it. Brain is getting foggy.

--
Gary S. Terhune
MS-MVP Shell/User
www.grystmill.com

"Paul Randall" <paulr901@xxxxxxxxxxxx> wrote in message
news:uv551Ce4HHA.4400@xxxxxxxxxxxxxxxxxxxxxxx
The command line reference a-z supplied with WXP tells you about
tasklist.exe. On my computer it resides in my system32 folder.

-Paul Randall

"Gary S. Terhune" <none> wrote in message
news:O2jEiwc4HHA.4676@xxxxxxxxxxxxxxxxxxxxxxx
After fixing the line return problems in the script, engendered by NG
transfer, I can't make it work. I get a command window flashing by,
then nothing. I'm using Calculator as a test, rather than Firefox,
which I don't have installed. Tried it in a command window, also, with
no return. Tried with Calc open and with it closed.

Using the command line in a command window, I get "'Tasklist'" is not a
recognized internal or external command, operable program or batch
file."

--
Gary S. Terhune
MS-MVP Shell/User
www.grystmill.com

"Pegasus (MVP)" <I.can@xxxxxxx> wrote in message
news:OjM25fb4HHA.1184@xxxxxxxxxxxxxxxxxxxxxxx
You can obtain the process ID of an active task, e.g. for
Firefox, with this command:
for /f "tokens=2" %a in ('tasklist ^| find /i "Firefox"') do echo %a

Here is the script equivalent:
Option Explicit
Const App = "FIREFOX"
Dim ObjWshShell, ObjExec
Dim ComSpec, SystemRoot, line

Set ObjWshShell = WScript.CreateObject("WScript.Shell")
ComSpec = ObjWshShell.Environment("PROCESS")("ComSpec")

Set ObjExec = ObjWshShell.Exec(ComSpec & " /c tasklist.exe")

line = ObjExec.StdOut.ReadLine
line = ObjExec.StdOut.ReadLine
While Len(line) > 0
If InStr(UCase(line), App) > 0 Then
line=LTrim(Right(line, Len(line) - InStr(line," ")))
WScript.Echo("Process ID for """ & App & """ is " &
Left(line,InStr(line," ")))
End If
line = ObjExec.StdOut.ReadLine
Wend


http://www.stadt-solothurn.ch/de/aktuelles/aktuellesinformationen/?action=showinfo&info_id=54610
"Gary S. Terhune" <none> wrote in message
news:emtBqhU4HHA.600@xxxxxxxxxxxxxxxxxxxxxxx
What apps? Oddly enough, while it's easy to run an app using a VB
script, I find no method to easily exit an app. But here's one
example of a kludge that will work for some apps. Using calculator as
an example (calc needs to already be open):

dim WshShell
set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.AppActivate "calculator"
WshShell.SendKeys "%{f4}"
WScript.Quit

Problem is, to identify the application and activate it requires the
name of the app as it appears in the title bar, or the Process ID.
I'm not sure how to obtain a Process ID, but that's what you'd want.
Using the title of the app is not useful in many cases, because it
varies. For example, while the title bar for Calculator is always the
same, apps like Word and IE list the open document's name, followed
by the app's name, like this: "My Test Document - Microsoft Word".

I'm curious: Why it's important that the apps be closed in the first
place.

--
Gary S. Terhune
MS-MVP Shell/User
www.grystmill.com

"116" <116@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:4B36897E-3D5E-4FED-8E20-E1ABD840DF51@xxxxxxxxxxxxxxxx
I am looking for some assistance in locating who to or perhaps some
sample
script for closing a running program. I am having difficulty with
people
shutting down app's when they go home for the evening. Perhaps
something
that I can Task Schedule to run every evening.

Thanks
David














.



Relevant Pages

  • Re: Closing a program with script...
    ... Switching to that PID and using Alt+F4 ... Say you have two instances of an app like Word open. ... The script generates no errors ... Tried it in a command window, also, with no ...
    (microsoft.public.windowsxp.general)
  • Re: Checking for running process
    ... > I've created a simple WSH script for the Win2000 computers in my kid's ... classroom that attempts to solve the problem of the kids launching multiple ... get impatient and click multiple times and launch the app a bunch of times. ... its own PID. ...
    (microsoft.public.scripting.wsh)
  • Re: Closing a program with script...
    ... After fixing the line return problems in the script, ... I'm using Calculator as a test, rather than Firefox, which I don't ... Tried it in a command window, also, with no return. ... If InStr, App)> 0 Then ...
    (microsoft.public.windowsxp.general)
  • Re: How to detect & kill a task
    ... Dim objShell, objExecObject, pid, app ... The script will end after it has killed Excel. ... It is not clear if he wants to monitor excel process creation or just to ...
    (microsoft.public.scripting.vbscript)
  • Re: How to detect & kill a task
    ... Dim objShell, objExecObject, pid, app ... The script will end after it has killed Excel. ...
    (microsoft.public.scripting.vbscript)

Quantcast