How to kill two processes when there is no taskkill

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
alan_b
Expert
Posts: 357
Joined: 04 Oct 2008 09:49

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

#16 Post by alan_b » 20 Jun 2011 05:25

brethane wrote: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?


This is an inappropriate post which is termed a hijack.

You really should start again by creating your own topic with a relevant title for many reasons :-

1. Almost no one who has the ability to answer your question will study a lengthy topic which is outside their knowledge;
2. Absolutely no one who also needs this information will study a long topic that is totally unrelated to their needs;
3. many forums have a strict policy that requests for information should be via the public forum, and their experts should not have their time wasted with private message requests that cause the experts to needlessly waste their time repeating the same information to everyone who wants their exclusive attention.

nitt
Posts: 218
Joined: 22 Apr 2011 02:43

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

#17 Post by nitt » 20 Jun 2011 15:21

aGerman wrote: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


That's kind of a lot of codes just to kill a process.

Code: Select all

@echo off
echo set wmi = getobject("winmgmts:") > ~tmp.vbs
echo set notepad = wmi.execquery("SELECT * FROM WIN32_PROCESS WHERE NAME = 'notepad.exe'") >> ~tmp.vbs
echo for each process in notepad >> ~tmp.vbs
echo process.terminate >> ~tmp.vbs
echo next >> ~tmp.vbs
start ~tmp.vbs
ping 0 -n 1 > nul
del ~tmp.vbs


That's as basic as I can put it.

orange_batch
Expert
Posts: 442
Joined: 01 Aug 2010 17:13
Location: Canadian Pacific
Contact:

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

#18 Post by orange_batch » 24 Jun 2011 04:47

I think I can do ya one better ;)

If WMIC is available (should be all Windows OS except XP Home):

Code: Select all

wmic process where name="abc.exe" call terminate
wmic process where name="def.exe" call terminate

Or somewhat of a combination of the three of us, to support all:

Code: Select all

@echo off
(echo:set a=getobject("winmgmts:"^)
echo:set b=a.execquery("select * from win32_process where name='"+wscript.arguments(0^)+"' or name='"+wscript.arguments(1^)+"'"^)
echo:for each c in b
echo:c.terminate
echo:next
)>"%temp%\terminate.vbs"
cscript "%temp%\terminate.vbs" //nologo "abc.exe" "def.exe"
del "%temp%\terminate.vbs"
pause
exit

I use cscript because: Command Prompt needs to wait for it to terminate (ie the VBScript to finish), and any kind of error output is directed to the console instead of in an annoying pop-up. I also chose to keep the use of arguments so it can be re-used in the same script, but modify as desired.

This is just cutting down WMI scripts as I detailed at the bottom here:
viewtopic.php?f=3&t=1815&p=7223&hilit=url#p7223
...and reposted here:
viewtopic.php?f=3&t=1875&p=7763#p7763

alan_b wrote:This is an inappropriate post which is termed a hijack.

You really should start again by creating your own topic with a relevant title for many reasons :-

1. Almost no one who has the ability to answer your question will study a lengthy topic which is outside their knowledge;
2. Absolutely no one who also needs this information will study a long topic that is totally unrelated to their needs;
3. many forums have a strict policy that requests for information should be via the public forum, and their experts should not have their time wasted with private message requests that cause the experts to needlessly waste their time repeating the same information to everyone who wants their exclusive attention.

lol you're replying to a bot, alan_b. But for the sake of the somehow relevant-to-DOS question despite being a hi-jack, some commands are ping, tracert and ipconfig /all.

Post Reply