Solved

batch file to kill iexplroe.exe

Posted on 2003-10-22
10
1,479 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
[X]
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
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
countClumps  challenge 10 235
countX 22 185
Advice in Xamarin 21 121
collection output issue 9 95
There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
This video teaches viewers about errors in exception handling.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

751 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