Page 1 of 2

How to kill two processes when there is no taskkill

Posted: 11 May 2011 04:30
by alan_b
This is a command that works on XP Pro and above

Code: Select all

taskkill /f /im abc.exe /im def.exe >> LOG.txt


I would like help applying this to XP Home.

I assume TSKILL will only kill one process at a time.
And I believe that needs PID numbers.

I would appreciate a simple script to :-
Detect whether it should use TASKKILL or TSKILL (or any alternative)
and to obtain PID numbers for killing abc.exe and def.exe

Regards
Alan

Re: How to kill two processes when there is no taskkill

Posted: 11 May 2011 04:40
by aGerman
Hi Alan.

As far as I remember you can use TSKILL with only the process name (without .exe). And yes, you need two command lines for two processes. An alternative could be the usage of WMI in VBScript.

Regards
aGerman

Re: How to kill two processes when there is no taskkill

Posted: 11 May 2011 04:51
by alan_b
Many thanks for rapid response.

Because Windows 7 came installed on a high powered Desktop I have been focussed on struggles with its differences from XP Home,
but sometime soon I will get back to XP Home on my low powered Laptop

Regards
Alan

Re: How to kill two processes when there is no taskkill

Posted: 11 May 2011 05:26
by aGerman
Just to show you an example how to include the VBScript to a batch code:

Code: Select all

@echo off &setlocal
(
  echo Set colProcesses = GetObject^("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2"^) _
  echo   .ExecQuery^("select * from win32_process where name='" ^& WScript.Arguments^(0^) ^& "' or name='" ^& WScript.Arguments^(1^) ^& "'"^)
  echo For Each objProcess in colProcesses
  echo   objProcess.terminate
  echo Next
)>"%temp%\terminate.vbs"

call "%temp%\terminate.vbs" "abc.exe" "def.exe"

del "%temp%\terminate.vbs"
pause

Regards
aGerman

Re: How to kill two processes when there is no taskkill

Posted: 11 May 2011 06:13
by alan_b
Thanks for the option, I assume this works for all flavours of Windows from XP Home and up.

If I was to avoid the VBS route how should I choose between TSKILL and TASKILL ?

Would the best CMD.EXE solution be something like

Code: Select all

IF EXIST %SYSTEMROOT%\System32\TSKILL (
  TSKILL abc >>  LOG.txt
  TSKILL def >>  LOG.txt
) ELSE (
  taskkill /f /im abc.exe /im def.exe >> LOG.txt
)


COFFEE BREAK - COFFEE INSPIRATION ! ! !

I have just realised that TSKILL is also present in Windows 7 Ultimate, so I guess VISTA also has it.

If TSKILL does what is needed on XP Home then :-
will it also be adequate for VISTA and Windows 7 ?
Does TASKILL give any benefit other than killing two processes at one time ?

Regards
Alan

Re: How to kill two processes when there is no taskkill

Posted: 11 May 2011 06:34
by aGerman
TASKKILL has more options and is more powerful because of the /F switch.
At home I have a machine with Win7 Starter where I will figure out whether TSKILL is available. (Currently I'm at work. I'll come back with this information in some hours.)

Regards
aGerman

Re: How to kill two processes when there is no taskkill

Posted: 11 May 2011 09:00
by alan_b
Thanks. Will appreciate info on Win7 Starter.

The intention is to uninstall a security application, so the /F may be essential.
Should I assume that TSKILL may fail due to its lack of /F ?

Would the VB script have superior removal power ?

Three factors make me VB averse :-

1. I have no skill for creating a VB script - I just hack at what I find on the Internet ;

2. XP Home has two VB engines, cscript and wscript,
and I never knew that until I had a problem and it was explained the wrong engine was using the code,
but I guess you have ensured the correct engine by using "WScript.Arguments"

3. It takes an eternity to prime the pumps and crank up the engine -
e.g. when I needed to know the time difference between File timestamps,
without VB I measured the difference to a resolution of 1 minute in less than 0.01 Seconds
using VB I measured the difference to a resolution of 1 second in what felt like 1 minute.

Regards
Alan

Re: How to kill two processes when there is no taskkill

Posted: 11 May 2011 10:10
by aGerman
alan_b wrote:Thanks. Will appreciate info on Win7 Starter.

You're welcome.
The result is that there's no tskill.exe on my Win7 Starter.


alan_b wrote:The intention is to uninstall a security application, so the /F may be essential.
Should I assume that TSKILL may fail due to its lack of /F ?

Yes, I already had this problem in the past. Latest I downloaded taskkill.exe from the internet to get this command run on my XP Home.


alan_b wrote:Would the VB script have superior removal power ?

As far as I tested - yes.


alan_b wrote:Three factors make me VB averse :-

1. I have no skill for creating a VB script - I just hack at what I find on the Internet ;

That's what I did in the past. Sometimes I had to customize such codes and for that reason I learned it step by step.


alan_b wrote:2. XP Home has two VB engines, cscript and wscript,
and I never knew that until I had a problem and it was explained the wrong engine was using the code,
but I guess you have ensured the correct engine by using "WScript.Arguments"

By default wscript.exe is associated to .vbs. (BTW WScript.Arguments has nothing to do with wich script engine is used.)
The main difference between the two script engines is that wscript is a Windows application and runs invisible while cscript runs in a console window. The last one is important to get the stdOut of the VBScript into a environment variable in a command line. For my example it's not interresting which engine is used.

alan_b wrote:3. It takes an eternity to prime the pumps and crank up the engine -
e.g. when I needed to know the time difference between File timestamps,
without VB I measured the difference to a resolution of 1 minute in less than 0.01 Seconds
using VB I measured the difference to a resolution of 1 second in what felt like 1 minute.

Once you called an 3rd party (also a command line tool -- remember our discussion about the ping command) it will waste your time. All you do with internal cmd functions (like FOR, SET etc.) is much faster. So for sure calling the VBScript will slow down your batch file because the script engine has to be loaded and the code has to be parsed ...
For that reason I normally avoid these Batch-VBScript-Chimeras and do the whole stuff in VBScript if there is no possibility in pure batch.

Regards
aGerman

Re: How to kill two processes when there is no taskkill

Posted: 11 May 2011 10:54
by alan_b
Many thanks.

I think the next thing for me to do is get XP Home up and running,
and try my proposed code that starts with "IF EXIST" to select either TSKILL or TASKKILL.

If that fails to beat the security settings then hopefully your VBS solution will be "strong enough" for XP,
and I hope will also not be fazed by any additional Access restrictions or UAC aggravations of Windows 7.

I am busy with Windows 7 at the moment, and it may be some days before I can get onto XP and provide feedback.

Regards
Alan

Re: How to kill two processes when there is no taskkill

Posted: 12 May 2011 01:21
by amel27
Hi, Alan.
CMD has native WMI client - WMIC.EXE:

Code: Select all

WMIC Process Where "Name='abc.exe' or Name='def.exe'" Call Terminate
Examples of WMIC commands for Windows .NET SERVER Family

Re: How to kill two processes when there is no taskkill

Posted: 12 May 2011 03:11
by aGerman
Hi amel27.

I had the same idea but WMIC isn't feasible because it's not available on XP Home.

Regards
aGerman

Re: How to kill two processes when there is no taskkill

Posted: 12 May 2011 03:59
by alan_b
Hi Amel

Thanks, that could be very useful.

I understand that your suggestion does the same as Taskkill.exe with the same authority over permissions issues.

Is your suggestion suitable for all versions of Windows from XP Home and upwards ?

I may have overstated my requirements.
I want the processes killed stone dead, but only until the next reboot when I want them fully alive again.
Please confirm that death by WMIC will not persist through a reboot.

I am overwhelmed by all that I am shown via "WMIC /?"
It concludes with
QUIT/EXIT - Exits the program.

Depending on how CMD.EXE is launched,
it may automatically close when it has done a job,
or it may persist until it is given the EXIT command.
Does WMIC have the same characteristic.
I assume that your suggestion does not result in a "dangling" WMIC waiting for an EXIT.

Using XP when CMD.EXE responded to HELP I never noticed WMIC,
but with W7 I now see
WMIC Displays WMI information inside interactive command shell.
Does XP Home not provide this, or was it protecting me from dangerous knowledge ! !
I notice that even W7 only admits to its display capability and says nothing about its control capabilities.

I am sorry for all my questions but WMIC.EXE examples indicate great power,
so I fear the consequences if I misunderstand and do the wrong thing.

Regards
Alan

Re: How to kill two processes when there is no taskkill

Posted: 12 May 2011 04:09
by alan_b
Thanks Amel

Nice try, I was getting excited.

Thanks aGerman

You saved me from a head banging experience.

Regards
Alan

Re: How to kill two processes when there is no taskkill

Posted: 12 May 2011 07:21
by amel27
alan_b wrote:Is your suggestion suitable for all versions of Windows from XP Home and upwards ?

I'm sorry, unfortunately, XP Home - unique system from XP which doesn't support this command (Vista Home support) :(
Alternatively I can offer inject WSH small procedure in BAT (CMD code between /* and */, other - JS):

Code: Select all

@set @x=0 /*
@echo off
cscript //nologo /e:jscript "%~f0" abc.exe def.exe
::
:: Other BAT Code
::
@exit */
for (i=0; i<WScript.Arguments.length; i++) {
  wmi = GetObject("winmgmts:").ExecQuery("SELECT * From Win32_Process Where Name='"+WScript.Arguments(i)+"'");
  for (var enu=new Enumerator(wmi); !enu.atEnd(); enu.moveNext()) enu.item().Terminate;
}

Re: How to kill two processes when there is no taskkill

Posted: 20 Jun 2011 03:59
by brethane
What is the DOS command which shows where incoming internet data is coming from? A friend showed me a DOS command which displays how many connections and the origin of data flowing to my PC (if that makes sense!). Please can someone let me know what the command is?