Solved

batch file to kill iexplroe.exe

Posted on 2003-10-22
10
1,476 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sumDigits challenge 9 149
method notes when mouse over in eclipse 5 87
pre4 challenge 19 100
Not seen Link button 5 39
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…
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 goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

772 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