Author Topic: Is there a way to script an "end process" in Windows?  (Read 140 times)

The Gorn

  • Your agonizer, please. And be sure to keep the batteries charged!
  • Trusted Member
  • Wise Sage
  • ******
  • Posts: 13730
  • Gornix user
    • View Profile
Is there a way to script an "end process" in Windows?
« on: February 12, 2010, 02:17:35 pm »
Here's a scenario that happens, not a lot for me, but often enough.

A misbehaving program needs to be clobbered. It could be an instance of Firefox that decides to not terminate itself and just hangs around, preventing a new instance from being launched.

Or it could be when my wife very occasionally runs into a popup for "scareware", that crap that says that it has run a "system check" and is asking you if you want to install their supposed AV solution. The "fix" here to avoid infection is to terminate the browser process, such as iexplore.exe.

The "proper" way to do these things is to launch Task Manager, look for the process in the process list (it will be listed by executable name), and right click to "End Process".

In each instance, it's generally the same program (by name) that occasionally I want to clobber.

What I would really prefer:

A desktop shortcut that I could set up that would do the same thing. IE, it would find a process instance of, say, IEXPLORE.EXE, and would terminate the process.

I know there are "problems" with this but they are mainly excuses for not providing a solution. IE: what if you have two or more instances with the same module (executable) name? I say, clobber the first one you find. Maybe just have the user keep applying the operation - it would be easier than opening up Task Manager.

Ideally, I want to set this up for my mother in law as a "panic button" in case she runs into scareware.

Any idea how to do this, Windows/admin gurus?

I can't believe there's no shareware around that does this in a canned way. I'm also sure that a Windows script could be written to this. I don't know how.
Gornix is protected by the GPL. *

* Gorn Public License. Duplication by inferior sentient species prohibited.


jbucks

  • Trusted Member
  • Wise Sage
  • ******
  • Posts: 625
    • View Profile
Don't have a canned "everything" answer.
« Reply #1 on: February 12, 2010, 02:23:24 pm »
But, I do have a batch file / script I'll post that allows me to kill an MS Access program if there's already one running.

Let me know if you're interested & I'll post it.


Jim

The Gorn

  • Your agonizer, please. And be sure to keep the batteries charged!
  • Trusted Member
  • Wise Sage
  • ******
  • Posts: 13730
  • Gornix user
    • View Profile
Is there a way to script an "end process" in Windows?
« Reply #2 on: February 12, 2010, 02:26:00 pm »
Quote from: jbucks
But, I do have a batch file / script I'll post that allows me to kill an MS Access program if there's already one running.

Let me know if you're interested & I'll post it.

Jim
Please do, you might learn me something.

I'm just looking for an example.

Gornix is protected by the GPL. *

* Gorn Public License. Duplication by inferior sentient species prohibited.


jbucks

  • Trusted Member
  • Wise Sage
  • ******
  • Posts: 625
    • View Profile
Here 'tis - NOT elegant or professional, but works for my needs.
« Reply #3 on: February 12, 2010, 03:17:19 pm »
This batch file is generally invoked like this:

D:\killMSAccessWithRunITK.bat d:\data\test.txt ITK_NetworkGeneralUtilities.mdb RunTRPrimaryWebExportOnly





REM @echo off
REM =======================================================================
REM File Name: killMSAccessWithRunITK.bat
REM      Date: July 01, 2008
REM    Author: Jim Bucks
REM
REM  Requires: Resource Kit Utilities kill.exe and tlist.exe put
REM            into a directory in the path. 
REM            %SYSTEMROOT% would be a good choice.
REM            Freeware blat program, also installed in the %SYSTEMROOT%
REM
REM  Required command line inputs (positional sensitive) you must pass in on the command line
REM        
REM            The first parameter,
REM                is the "log file" location and name
REM            The second parameter,
REM                is the name of the MS Access code file name
REM                   current ones are either WebExportUtility.mdb or ITKNetworkUtilities.mdb
REM            The third parameter,
REM                is the name of the entrance point within the Access code file
REM                   there are many of these, and they can differ within each Access code file.
REM
REM          Here is an example invocation of the command line to be used.
REM             killMSAccess.bat d:\data\test.txt WebExportUtility.mdb AutoFileExport2nd
REM
REM
REM    Intent: This batch file is to support the hourly Web Export for
REM                Doug's InTheKnow utils.
REM            The first check is to see if a MSACCESS.EXE is already
REM                running.  If so, kill it. 
REM            The risk here is that if a valid MSACCESS.EXE
REM                process running, it will be killed.
REM
REM     Notes:  This version of the file is for Windows Server 2003 only
REM
REM             Updated this specific file to run on Windows Server 2003.
REM             The old kill.exe will not run on W2k3 - use taskkill.exe
REM             The old tlist.exe will not run on w2k3 - use tasklist.exe
REM             No longer need to use tlist / tasklist - can call the process
REM               name directly from taskkill.exe.
REM
REM
REM             It'll kill any running msaccess processes, then invoke
REM             the desired ITK process.
REM
REM
REM ******************************************************

set out_file_name=%1
set itk_flavor=%2
set itk_command=%3
set email_addresses="number2@xxx.com, number2@yyy.com, number3@yyy.com, number4@zzz.net"
set email_subject="ITK01 taskkill has been run.  Running MS Access processes were killed"


tasklist.exe | FIND /i "msaccess.exe" > %out_file_name%
taskkill.exe /F /IM msaccess.exe


REM ******************************************************
REM Check if found any running - hung msaccess processes and email if any were found.
REM A zero length file means no ms access processes were found running.
REM A greater than zero length file means something was found - and an email is sent out via blat as an alert to do some checking.
REM ******************************************************
if %~z1 GTR 0 (
blat %out_file_name% -to %email_addresses% -subject %email_subject%
)

REM ******************************************************
REM Housekeeping to make sure there are no leftovers that might cause problems.
REM ******************************************************
del %out_file_name%

REM ******************************************************
REM Now let's kill any stray "lock" files - WebExportUtility.ldb
REM ******************************************************
del "c:\Program Files\inTheknow\WebExportUtility.ldb"

REM ******************************************************
REM This is the command line from Doug's hourly scheduled web export task.
REM  Uses the 2nd & 3rd passed in parameters from the command line.
REM  sample command line: killMSAccessWithRunITK.bat d:\data\test.txt WebExportUtility.mdb AutoFileExport2nd
REM ******************************************************
"D:\apps\Microsoft Office\OFFICE11\MSACCESS.EXE" "c:\Program Files\InTheKnow\%itk_flavor%" /wrkgrp "C:\Program Files\InTheKnow\MMT_ITK.mdw" /user "blech" /pwd "blah" /cmd %itk_command%

REM pause
cls
exit


« Last Edit: February 12, 2010, 03:20:24 pm by jbucks »

The Gorn

  • Your agonizer, please. And be sure to keep the batteries charged!
  • Trusted Member
  • Wise Sage
  • ******
  • Posts: 13730
  • Gornix user
    • View Profile
Thank you!
« Reply #4 on: February 12, 2010, 03:33:07 pm »
The key is the single statement:

taskkill.exe /F /IM BLABLA.EXE

Replace BLABLA.EXE with the executable name of the process you wish to clobber. IE, to kill Internet Explorer the command becomes

taskkill.exe /F /IM iexplore.exe

On Windows 7 it must be run at Administrative level. But it does work.
Gornix is protected by the GPL. *

* Gorn Public License. Duplication by inferior sentient species prohibited.


pxsant

  • Global Moderator
  • Wise Sage
  • *****
  • Posts: 1116
    • View Profile
Taskkill
« Reply #5 on: February 12, 2010, 03:53:41 pm »
It appears that  Taskkill  will do what you want.

The Gorn

  • Your agonizer, please. And be sure to keep the batteries charged!
  • Trusted Member
  • Wise Sage
  • ******
  • Posts: 13730
  • Gornix user
    • View Profile
Is there a way to script an "end process" in Windows?
« Reply #6 on: February 12, 2010, 03:58:10 pm »
Thanks. Jbucks had already provided an example of the command line that works perfectly.

I was just too damned lazy to Google for it.

I intend to write a short batch file for my wife and for my mother in law and set up a desktop "Panic Button" shortcut that points to it, for them to use if they run into scareware.
Gornix is protected by the GPL. *

* Gorn Public License. Duplication by inferior sentient species prohibited.


The Gorn

  • Your agonizer, please. And be sure to keep the batteries charged!
  • Trusted Member
  • Wise Sage
  • ******
  • Posts: 13730
  • Gornix user
    • View Profile
Solution - here is a .bat file that clobbers IE and Firefox, instantly
« Reply #7 on: March 03, 2010, 01:20:16 am »
Just the thing for pr0n users.  ;)

If you wanted to get rid of either or both of these web browsers instantly, here are the contents of  .bat file that does just that.

Code: [Select]
taskkill.exe /F /IM iexplore.exe
taskkill.exe /F /IM firefox.exe

And set a shortcut to point to this bat file.

Note - in Windows Vista or Windows 7 you will have to Shortcut Properties, Advanced button, and check the "Run as Administrator" checkbox. Then probably answer yes to a UAC prompt, unless you disabled UAC.

Works for me.
Gornix is protected by the GPL. *

* Gorn Public License. Duplication by inferior sentient species prohibited.



Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf