Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

batch file to kill iexplroe.exe

Posted on 2003-10-22
10
1,477 Views
Last Modified: 2007-12-19
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
Comment
Question by:net-geek
  • 5
  • 5
10 Comments
 
LVL 16

Expert Comment

by:_nn_
ID: 9599199
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
 

Author Comment

by:net-geek
ID: 9599754
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
 
LVL 16

Accepted Solution

by:
_nn_ earned 125 total points
ID: 9599801
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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:net-geek
ID: 9600875
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
 

Author Comment

by:net-geek
ID: 9600882
I forgot to increment the points..sorry!
0
 

Author Comment

by:net-geek
ID: 9601970
I figured taht out....I wrote a VB code that runs in the background. I trulya ppreciate your help. Thanks!
0
 

Author Comment

by:net-geek
ID: 9602170
Could you please explain the working of the batch file you wrote.
0
 
LVL 16

Expert Comment

by:_nn_
ID: 9603127
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
 
LVL 16

Expert Comment

by:_nn_
ID: 9603133
Oh, the prefered place to ask about batch programming on EE is actually
http://www.experts-exchange.com/Operating_Systems/MSDOS/
0
 
LVL 16

Expert Comment

by:_nn_
ID: 9603179
>> 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
countEvens challenge 2 111
Python 2.7 - French characters 6 103
wordappend challenge 8 200
Problem to Alipay 10 43
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question