?
Solved

Batch File: Active Window

Posted on 2010-09-15
9
Medium Priority
?
2,457 Views
Last Modified: 2012-05-10
Hi there,

Please review the included script.

After starting Internet Explorer, I need to bring the Batch File CMD window back as active (focused), without me having to click in it.

And while at it, how can I "taskkill" only the Internet Explorer's PID I just opened?

Thanks for your help,
Rene
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION

SET EmailListSource=EmailListSource.txt
SET YesFile=%~n0_YES.txt
SET  NoFile=%~n0_NO.txt

IF NOT EXIST %YesFile% ECHO.>%YesFile%
IF NOT EXIST %NoFile% ECHO.>%NoFile%


FOR /F "TOKENS=3,4 DELIMS=;" %%A IN (%EmailListSource%) DO (
	FOR /F "tokens=2 delims=@" %%B in ("%%A") DO (
		TYPE %YesFile% | Findstr "%%B">NUL
		IF !errorlevel! NEQ 0 TYPE %NoFile% | Findstr "%%B">NUL
		IF !errorlevel! NEQ 0 CALL :Menu "%%B" 
	)
)


PAUSE
EXIT



:Menu
CHOICE /C 123 /M "%~1   (1=Yes 2=No 3=Review 0=Exit)  "
IF %errorlevel% == 1 ECHO %~1>>%YesFile%
IF %errorlevel% == 2 ECHO %~1>>%NoFile%
IF %errorlevel% == 3 (
	START "C:\Program Files\Internet Explorer\iexplore.exe" http://www.%~1
	ECHO.
	PAUSE
	ECHO.
	TASKKILL -f -im iexplore.exe
	GOTO Menu
)

EXIT /b

Open in new window

0
Comment
Question by:ReneGe
[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
  • 4
9 Comments
 
LVL 56

Expert Comment

by:Bill Prew
ID: 33687996
I think you can use the WIN command in NIRCMD to set the CMD window back to thetop.

http://www.nirsoft.net/utils/nircmd2.html#using

~bp
0
 
LVL 56

Expert Comment

by:Bill Prew
ID: 33688003
As far as killing the IE instance you start, try adding the window title to the START command, and then search for that in the kill.

START "MYIE" "C:\Program Files\Internet Explorer\iexplore.exe" http://www.%~1

~bp
0
 
LVL 10

Author Comment

by:ReneGe
ID: 33688035
Hey bp & bp ;-)

1) Could there be a way without using a util?
2) The IE window does not take the title.

However, I found a way to get it's PID (from nummagumma2):
http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/Q_24718446.html

So killing the right process is resolved. Do you this we may be able to bring back the focus to the CMD window without the util?

Thanks and cheers,
Rene
@echo off
psexec -s -d "c:\program files\Internet Explorer\iexplore.exe" http://www.mysite.dom
set pid=%errorlevel%
sleep 10
pskill %pid%

Open in new window

0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 10

Author Comment

by:ReneGe
ID: 33688040
Actually it is without the -s because it will run in the system account and will not see it.


@echo off
psexec -d "c:\program files\Internet Explorer\iexplore.exe" http://www.mysite.dom
set pid=%errorlevel%
sleep 10
pskill %pid%

Open in new window

0
 
LVL 56

Expert Comment

by:Bill Prew
ID: 33688053
Does the IE window need to be visible while it's running?  If not you might be able to start it hidden or minimized and not lose focus.

~bp
0
 
LVL 10

Author Comment

by:ReneGe
ID: 33688079
I have 2 screens.

CMD windows is on screen 1.

When the batch file opens I.E., I.E. opens on screen 2 and I need to see it.

Then, the focus must come back to the batch file CMD without the need for me the click in it.

If it is impossible in a batch file, I dont mind using a VBScript.

Thanks,
Rene
0
 
LVL 10

Author Comment

by:ReneGe
ID: 33688087
And if it would all just be easyer for you to do all in VBScript, that is still fine with me.

Thanks and cheers,
Rene
0
 
LVL 56

Accepted Solution

by:
Bill Prew earned 2000 total points
ID: 33688256
I don't think there's any native way for the batch file to regain control and pop its window back up.  But we'll see if any other experts chime in.

~bp
0
 
LVL 10

Author Comment

by:ReneGe
ID: 33688455
I must have this running soon.
So I guess I'll have to use a util.
I found this: http://www.commandline.co.uk/cmdow/#examples that seems easy to use.

However, to use it' I will need to get the PID of my running batch file window.

I'll use:

for /F "Tokens=3" %%I in ('C:\Tools\getpids.exe') do set XX1PID=%%I
if "%XX1PID%" == "" (

      echo.
      echo ===^> ERROR: The current process id could not be retrieved.
      echo.

      goto Exit
)

Thanks for your help bp!

Cheers,
Rene
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
A short article about problems I had with the new location API and permissions in Marshmallow
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

770 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