Need batch file help

  • Thread starter Thread starter tech
  • Start date Start date
T

tech

What I'm trying to do is start a batch file loop that tests for IE, so
that when I close IE, it will terminate another program. I haven't had
much luck in finding an environmental variable for IE. I know there's
probably some utility out there that will do it, but I want to learn
how to do it with a batch file. Can anyone help with this? Thanks
 
tech said:
What I'm trying to do is start a batch file loop that tests for IE, so
that when I close IE, it will terminate another program. I haven't had
much luck in finding an environmental variable for IE. I know there's
probably some utility out there that will do it, but I want to learn
how to do it with a batch file. Can anyone help with this? Thanks

When you say "test for IE" then I assume you mean "test if IE is
currently running". If so then you can do this:

@echo off
tasklist | find /i "iexplore" && taskkill /im sometask.exe
 
OOPS, should have mentioned I'm running XP Home, it doesn't have the
extended batch commands of XP Pro.
 
tech said:
OOPS, should have mentioned I'm running XP Home, it doesn't have the
extended batch commands of XP Pro.

There is nothing extended here. Give it a try!
 
I had read that XP home does not support tasklist and taskkill.
But just to be sure, I typed them at the command prompt, and they were
not recognized. I think the && symbols are not supported either.

I found pstools and am now trying pskill and pslist, but no luck
converting to your command yet.

Looks like you're checking for IEexplore in the task list, and passing
the image name to taskkill if not found? I'm guessing this command
would keep searching until IExplore is not found, and then continue to
the next line in the batch file?

Another weird thing is that IExplore.exe is not listed in the process
list while running. That really confused me!
 
tech said:
I had read that XP home does not support tasklist and taskkill.
But just to be sure, I typed them at the command prompt, and they were
not recognized. I think the && symbols are not supported either.

I found pstools and am now trying pskill and pslist, but no luck
converting to your command yet.

Looks like you're checking for IEexplore in the task list, and passing
the image name to taskkill if not found? I'm guessing this command
would keep searching until IExplore is not found, and then continue to
the next line in the batch file?

Another weird thing is that IExplore.exe is not listed in the process
list while running. That really confused me!

As Ramesh pointed out, tasklist.exe and taskkill.exe may not
be included in WinXP Home.

Using the tools from SysInternals, the batch file is much the
same as before:

@echo off
c:\tools\pslist | find /i "iexplore" && c:\tools\pskill sometask.exe

Now I'm convinced that the && operator is supported
under WinXP. However, if you insist then you can run
the same batch file without it:


@echo off
c:\tools\pslist | find /i "iexplore"
if not ErrorLevel 1 c:\tools\pskill sometask.exe

What makes you think that iexplore.exe is not listed in
the task list when it's active? Please explain!

Lastly, to test your batch file properly you must run it from
a Command Prompt and ***not*** from the Run box.
When you Run it from the run box then you deprive yourself
of any feedback you might get, which is a terrible way of
testing a batch file while in unfamiliar territory.
 
I have checked task manager, in fact I'm doing it now. Iexplore is not
listed, even though I'm using it right now.

Yes, I've ran numerous tests at the command prompt. It runs pslist, but
ignores everything else, no matter the condition. This leads me to
believe that maybe && isn't supported.

This batch works, but the loop takes up a lot of cpu usage. I am
substituting nft , since I can't see iexplore in the processes. It will
terminate TE.exe when nft is closed, and end the batch file.

:loop
pslist nft || pskill -t TE.exe || exit
goto loop
 
I recommend you test my version of the batch file, then
report on it. Yours does something completely different.

@echo off
c:\tools\pslist | find /i "iexplore"
if not ErrorLevel 1 c:\tools\pskill sometask.exe

You should also do this from a Command Prompt while
Internet Explorer is running, then paste the notepad screen
into your next reply:

pslist > c:\test.txt
notepad c:\test.txt
 
Cool, I didn't know people still wrote BAT files
http://www.microsoft.com/technet/scriptcenter/default.mspx

|I recommend you test my version of the batch file, then
| report on it. Yours does something completely different.
|
| @echo off
| c:\tools\pslist | find /i "iexplore"
| if not ErrorLevel 1 c:\tools\pskill sometask.exe
|
| You should also do this from a Command Prompt while
| Internet Explorer is running, then paste the notepad screen
| into your next reply:
|
| pslist > c:\test.txt
| notepad c:\test.txt
|
|
|
| | > I have checked task manager, in fact I'm doing it now. Iexplore is
not
| > listed, even though I'm using it right now.
| >
| > Yes, I've ran numerous tests at the command prompt. It runs
pslist, but
| > ignores everything else, no matter the condition. This leads me to
| > believe that maybe && isn't supported.
| >
| > This batch works, but the loop takes up a lot of cpu usage. I am
| > substituting nft , since I can't see iexplore in the processes. It
will
| > terminate TE.exe when nft is closed, and end the batch file.
| >
| > :loop
| > pslist nft || pskill -t TE.exe || exit
| > goto loop
| >
|
|
 
The latest form of your batch file also doesn't perform past pslist. So
maybe the FIND function is where it stops working. But just to clarify
things, I want to load the TE tsr, then load Iexplore, then have the
batch to keep checking for Iexplore until it is closed. It will then
kill the TE tsr and end the batch file. Remember that I'm substituting
nsr for iexplore for test purposes at this point. I have done the same
with your batch.

here is your request:

Name Pid Pri Thd Hnd Priv CPU Time Elapsed
Time
Idle 0 0 1 0 0 0:00:59.671
0:00:00.000
System 4 8 62 300 0 0:00:16.093
0:00:00.000
smss 376 11 3 21 164 0:00:00.500
0:04:37.578
csrss 436 13 11 437 1672 0:00:07.671
0:04:36.390
winlogon 464 13 19 426 5972 0:00:01.593
0:04:35.500
services 508 9 16 282 1916 0:00:08.125
0:04:35.171
lsass 520 9 20 338 3540 0:00:00.703
0:04:35.125
svchost 664 8 18 193 2896 0:00:00.140
0:04:34.218
svchost 728 8 9 277 1604 0:00:00.234
0:04:33.843
svchost 764 8 79 1351 11684 0:00:04.062
0:04:33.734
svchost 816 8 7 87 1192 0:00:00.046
0:04:33.640
svchost 916 8 14 197 1636 0:00:00.093
0:04:32.890
explorer 1296 8 21 508 19528 0:00:10.859
0:04:31.812
spoolsv 1332 8 15 148 3164 0:00:00.203
0:04:31.781
smax4pnp 1520 8 3 79 2424 0:00:00.203
0:04:30.734
hkcmd 1536 8 2 81 1388 0:00:00.296
0:04:30.703
IntelMEM 1564 8 2 22 864 0:00:00.078
0:04:30.671
avgcc 1584 8 7 168 2988 0:00:00.546
0:04:30.484
nft 1600 8 1 84 828 0:00:00.296
0:04:30.265
avgamsvr 1636 8 9 130 1968 0:00:00.296
0:04:28.171
avgupsvc 1684 8 4 77 488 0:00:00.015
0:04:27.968
avgemc 1724 8 9 151 1908 0:00:00.312
0:04:27.890
svchost 1904 8 7 121 2292 0:00:00.109
0:04:26.750
wdfmgr 120 8 6 67 1496 0:00:00.015
0:04:26.171
alg 1128 8 6 104 1040 0:00:00.031
0:04:22.640
wuauclt 220 8 7 177 6348 0:00:00.140
0:03:39.906
cmd 692 8 1 19 1440 0:00:19.265
0:03:36.328
TE 912 8 10 311 4852 0:00:03.296
0:03:36.031
cmd 208 8 1 32 1892 0:00:00.062
0:00:25.156
pslist 2988 13 2 84 684 0:00:00.046
0:00:00.015

iexplore is not shown in the process list, but does show in
applications. My version of the batch is running also, you can see it's
really eating up cpu time....
 
I love statements such as "The latest form of your batch
file also doesn't perform past pslist". Since you do not
report the exact version of what you run and what exactly
happens when you do run it, I have no way of determining
what "doesn't perform" really means. I suspect that you
use the wrong symbol for the pipe connector but until you
post your version of the batch file - verbatim! - I have no
way of telling.

If iexplore does not show up in the list of currently running
tasks then I guess there is something drastically wrong
with your machine. Virus? Malware?
 
Sorry, didn't mean to insult you. Thanks for your help. But we're
probably pulling teeth here, working with 2 different versions of
XP.(XP Home, SP2)(IE 6, SP2) I can't provide any more information than
already posted. Information provided was cut and pasted, so there's no
typo. There are no known viruses or malware detected, using the most
recent definitions.
 
tech said:
Sorry, didn't mean to insult you. Thanks for your help. But we're
probably pulling teeth here, working with 2 different versions of
XP.(XP Home, SP2)(IE 6, SP2) I can't provide any more information than
already posted. Information provided was cut and pasted, so there's no
typo. There are no known viruses or malware detected, using the most
recent definitions.

You did not insult me at all, you just did not provide
enough information to resolve the problem. Attaching
your batch file would go a long way towards finding
out what's going on.
 
Yeah, I didn't post the first 2(of 5) lines because they are simple
START commands. I thought it was implied, but after rereading my posts,
I guess didn't make that obvious until halfway through. If there is
another way to check for IE besides the process list, I'd be glad to
hear it.
 
tech said:
Yeah, I didn't post the first 2(of 5) lines because they are simple
START commands. I thought it was implied, but after rereading my posts,
I guess didn't make that obvious until halfway through. If there is
another way to check for IE besides the process list, I'd be glad to
hear it.

Post your batch file as an attachment.
 
Back
Top