Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1488
  • Last Modified:

batch file to kill iexplroe.exe

I need to write a batch file that kills the process iexplore.exe whenever more than one instnace of it is running. Still better would be to kill all and leave just one. My objective is to have only a single instance of internet explorer after the batch file is run.

I am ready to give mroe points if you think writing such a batch file  is more involved.

Please fell free to guide me using any other language or MS tool to accomplish the task of having just one instance of iexplore.exe.
0
net-geek
Asked:
net-geek
  • 5
  • 5
1 Solution
 
_nn_Commented:
Provided you have PsTools from sysinternals http://www.sysinternals.com/ntw2k/freeware/pstools.shtml , I would use :

for /f "skip=1 tokens=1,2" %a in ('pslist ^| find /I "iexplore"') do pskill %b

Within a batch file, % must be "doubled", so :
for /f "skip=1 tokens=1,2" %%a in ('pslist ^| find /I "iexplore"') do pskill %%b
0
 
net-geekAuthor Commented:
I tried executing the batch file with multiple explorer windows open, but nothing happened. I am not at all familair with batch files so I just want to reconfirm if this is all I write in the file. I am increasing the points to 100 just in case it requires extra effor on your part to give me the entire thing or if it is all I need, may be you can assist me in running it properly.

0
 
_nn_Commented:
On my Win2K box, it works flawlessly.

- what is your operating system ?
- the line should be :

for /f "skip=1 tokens=1,2" %%a in ('pslist ^| find /I "iexplore"') do pskill %%b

- do you have pslist.exe and pskill.exe in the same directory as the batch or somewhere in the path ?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
net-geekAuthor Commented:
It works like a charm!!!!!!!!!!!!!!!!!

I am increasing points by another 25 as now I have another issue. I want this to be running in the background but I just realized that teh batch file is going to run just once.

Please advice if I should schedule the batch file to run after every 5 minutes OR I write a code in VB that runs in teh background. I know VB and can think of doing it but if you have an easier way out, please let me know.

I can not thank you enough, so even if the problem of running it continuously in the background is not solved, I am gonna give you allt he points.If you can direct me to a good learning source for batch files, i would appreicate it.

0
 
net-geekAuthor Commented:
I forgot to increment the points..sorry!
0
 
net-geekAuthor Commented:
I figured taht out....I wrote a VB code that runs in the background. I trulya ppreciate your help. Thanks!
0
 
net-geekAuthor Commented:
Could you please explain the working of the batch file you wrote.
0
 
_nn_Commented:
Thanks for the points :)

The simplest way to make it run regularly is to make a loop with a pause

@echo off
:again
for /f "skip=1 tokens=1,2" %%a in ('pslist ^| find /I "iexplore"') do pskill %%b
:: following will wait about 5 mins
ping -n 301 127.0.0.1 >NUL
:: and loop
goto again

>> If you can direct me to a good learning source for batch files, i would appreicate it.

There are tons of. A google search with "batch", "DOS", "cmd", etc should already return a load of links. One of my bookmarks :
http://www.microsoft.com/technet/treeview/default.asp?url=/technet/prodtechnol/windows2000serv/support/faqw2kcp.asp

I'll send more when I'll get back in the office tomorrow.
0
 
_nn_Commented:
Oh, the prefered place to ask about batch programming on EE is actually
http://www.experts-exchange.com/Operating_Systems/MSDOS/
0
 
_nn_Commented:
>> Could you please explain the working of the batch file you wrote.

You should read the help for the for command

for /?

In the line

  for /f "skip=1 tokens=1,2" %%a in ('pslist ^| find /I "iexplore"') do pskill %%b

there is first a command :

  pslist | find /I "iexplore"

So, the output of pslist is first filtered and only lines with "iexplore" (/I means regardless of case) are kept. The result is a certain number of lines which gets processed by the "for" command itself. The options specified after the /f do the "trick". 'skip' tells the command processor to skip one (the first) line of the output. Then, each line is tokenized, that is, each 'words' separated by spaces gets distributed in variables. So since I chose %%a and said I wanted the first 2 words of the line, I'm ending up getting the process name in %%a (which isn't interesting here since I know it's "iexplore.exe") and the PID of the process in %%b, and so on (a third token would have been stored in %%c, etc). The command after the "do" gets executed. Final result :
- if one or less iexplore processes, nothing happens
- if two or more, the second up to the last iexplore.exe gets killed
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now