End application using batch file

On a Win2000 SP4 Workstation, can a batch file be written and run on the local workstation to shut down an application? I can use a restart Windows command, and set Windows to automatically login, but prefer not to for security reasons.
esc_toe_accountAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

esc_toe_accountAuthor Commented:
I want to close Outlook XP, if it is running.
0
esc_toe_accountAuthor Commented:
(See also question http://www.experts-exchange.com/Applications/MS_Office/Outlook/Q_20805390.html Am trying to get a backup of the Outlook .pst file, which needs Outlook to be shut down first.)
0
svenkarlsenCommented:
Yes,

if you're ok with advanced batch-coding, what you basically do is:

 - use TLIST -m [exe-filename] to get the PID of the Outllok XP
 - use KILL [PID] to stop the program

(don't be scared by kill, - it's gracefull as lon as you don't use -f (FORCE!))

Have a look at "FOR /F...:" in the OS help-file, - that will do it in one line!



Regards,
Sven




0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

esc_toe_accountAuthor Commented:
That is a little advanced for me. I find this example for getting the PID of a running batch process:

for /f "Tokens=*" %%I in ('f:\tlist ^| grep %0 ^| grep CMD ^| awk "{ print $1 }"') do call :SETPID %%I
:next
.......
:SETPID
set MASTER_PID=%1
goto :next
.......

Could I edit this? The application is OUTLOOK.EXE

Thanks!
0
oBdACommented:
No real need for that construction.
kill.exe accepts a pattern as well as a PID. A simple
kill outlook.exe
should do the trick.
0
esc_toe_accountAuthor Commented:
How would I call kill? I've tried a couple of ways without success
0
esc_toe_accountAuthor Commented:
I've tried looking up the PID in Task Manager to get such as

Kill 1096

.. but that hasn't worked either.
0
esc_toe_accountAuthor Commented:
I see this reference:

Windows NT/2000 does not come with a command-line 'kill' utility. You can get one in the Windows NT or Win2K Resource Kit.

So, I'm going to try Sysinternals PSKILL utility.
0
oBdACommented:
Stupid me. Let me guess, it tells you that the command can't be found.
Install the Support Tools; they're on the W2k installation CD (support\tools), but do NOT install them from there. Some of them get updated by Service Packs as well; so download (and install) the version matching your service pack's version:
Windows 2000 Service Packs
http://www.microsoft.com/windows2000/downloads/servicepacks/
0
oBdACommented:
PsKill should do the trick as well, but the Support Tools are worth installing anyway. tlist.exe comes with them as well, by the way.
0
esc_toe_accountAuthor Commented:
I have SP4, but it's not clear to me how to install the support tools from there.
0
esc_toe_accountAuthor Commented:
pskill OUTLOOK.EXE does give the Outlook application focus (the button depresses on the taskbar when all windows are minimized), but it doesn't end or change it in any way.
0
esc_toe_accountAuthor Commented:
Ditto regardless of whether I use the PID (1096, for now) or OUTLOOK.EXE
0
esc_toe_accountAuthor Commented:
The entire content of my test.bat file is:
------------------------------------------------------------
echo off
pskill OUTLOOK.EXE
cls
------------------------------------------------------------
0
esc_toe_accountAuthor Commented:
PSKILL Usage:
------------------------------------------------------------------------
Running PsKill with a process ID directs it to kill the process of that ID on the local computer. If you specify a process name PsKill will kill all processes that have that name.
------------------------------------------------------------------------
usage: pskill [-?] [\\computer [-u username] [-p password]] <process name | process id>
    -? Displays the supported options.
   \\computer Specifies the computer on which the process you want to terminate is executing. The remote computer must be accessible via the NT network neighborhood.
    -u username If you want to kill a process on a remote system and the account you are executing in does not have administrative privileges on the remote system then you must login as an administrator using this command-line option. If you do not include the password with the -p option then PsKill will prompt you for the password without echoing your input to the display.
    -p password This option lets you specify the login password on the command line so that you can use PsList from batch files. If you specify an account name and omit the -p option PsList prompts you interactively for a password.
    process id Specifies the process ID of the process you want to kill.
    process name Specifies the process name of the process or processes you want to kill.
0
esc_toe_accountAuthor Commented:
However, when I try it from a command prompt, it works fine.
0
oBdACommented:
It's not included in the Service Pack itself. The link was meant for you to go to "your" service pack site from the link above, then look a bit further down for the "Support Tools" download link.
For Service Pack 4, the direct link is here:
Windows 2000 SP4 Support Tools
http://www.microsoft.com/windows2000/downloads/servicepacks/SP4/supporttools.asp
0
oBdACommented:
Oh, and since this is in preparation for a backup, you might need the "-f" switch; if a user has an open/unsaved document (email or whatever), the application to be killed will ask whether to save the data, and it won't be shut down until this message box has been answered.
Test this before you apply it in earnest on a "life" system; I don't know how Outlook reacts to being shut down with open documents.
0
esc_toe_accountAuthor Commented:
My error. Thanks! I have done so, and now the error message is: ||'||' is not recognized, etc. -- this is the same error I was getting with pskill

(where || is a nonstandard ASCII character)
0
esc_toe_accountAuthor Commented:
It still works from a command prompt (as pskill did) and still does not work from a batch file.
0
esc_toe_accountAuthor Commented:
.. and my existing batch files still work normally (successfully).
0
oBdACommented:
Hm? kill.exe should work in bat files as well. Try this little script, which will open three calculators, wait for a key and then close all calculators again.

====8<----[test.cmd]----
@echo off
echo Now starting the calculator ...
start "" calc
start "" calc
start "" calc
echo Hit any key to close any open calculator ...
pause >NUL
kill -f calc.exe
====8<----[test.cmd]----
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
esc_toe_accountAuthor Commented:
1. It opens three calculators.

2. If I restore the focus to the command window, the command window closes when I hit a key.
0
oBdACommented:
I guess you are starting the command file using explorer? For debugging, it's easier to start it from a command prompt.
Anyway, you left out the most interesting part: did the calculators disappear after you hit a key?
0
esc_toe_accountAuthor Commented:
No calculators close (I only described what DID happen, not what DIDN'T--sorry for the confusion). For example, if I don't restore focus to the command window, pressing a key simply operates on the last calculator open. (If an application has focus, this is expected behavior--right?--regardless of how it was opened?)

Works the same regardless whether run from:
  1. Command prompt (Start-->Run-->cmd or command/Enter)
  2. Explorer
  3. Start-->Run-->test.bat/Enter.

0
oBdACommented:
While I'm at it: Don't use "command" in NT. That's the "original"  DOS running in the NTVDM and only good for headaches, apart from the reduced functionality.
Just use "cmd" or %comspec%.
When you start it from the command prompt, is there any error output?
Have you tried providing the full path for kill.exe? It's probably something like this:
"C:\Program Files\Support Tools\kill.exe" -f calc.exe
0
esc_toe_accountAuthor Commented:
Sorry for delay .. will finalize this soon .. the original problem PC was rotated out of service and has only just come back into service .. will try again.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows 2000

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.