Solved

batch file to kill iexplroe.exe

Posted on 2003-10-22
10
1,469 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_
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:net-geek
Comment Utility
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
Comment Utility
I forgot to increment the points..sorry!
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:net-geek
Comment Utility
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
Comment Utility
Could you please explain the working of the batch file you wrote.
0
 
LVL 16

Expert Comment

by:_nn_
Comment Utility
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_
Comment Utility
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_
Comment Utility
>> 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Opening a Access Database 5 121
Rock, Paper and Scisssors Game Logic Question 7 58
equalIsNot  challenge 43 115
Hibernate methods 2 58
Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
The viewer will learn how to implement Singleton Design Pattern in Java.

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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now