Solved

Make an active batch file window visible after starting browser

Posted on 2011-02-27
30
743 Views
Last Modified: 2012-06-27
I've got a batch file that handles an installation for clients. At one point it opens a browser window and later requires input; i.e.
download file
move file
start instructions.htm
Choice /c yn
continue installation
start thankyou.htm
exit

The problem is that instructions.htm covers up the command window and a novice user would never notice. I need the batch process to pop back so that it is layered over the top of the browser window. I thought that start /wait would do it but not so. Any suggestions?
0
Comment
Question by:ProTek2
  • 12
  • 5
  • 4
  • +2
30 Comments
 
LVL 1

Expert Comment

by:markdormer
ID: 34993811
If you call a vbscript file that contains this code it will give the focus to the batch file Window.

    set WshShell = WScript.CreateObject("WScript.Shell")
         WshShell.AppActivate "Command Prompt"
0
 
LVL 14

Assisted Solution

by:Psy053
Psy053 earned 100 total points
ID: 34993821
In your batch file, you could include the following lines:

What it does it creates a VBS File, and then runs it.

The VBS file uses the AppActivate Method to bring the Command Prompt window to the front.
echo set WSHShell = WScript.CreateObject("WScript.Shell") > "C:\Data\Scripts\CMD_Scripts\AppAct.VBS"
echo WSHShell.Appactivate "C:\Windows\system32\cmd.exe" >> "C:\Data\Scripts\CMD_Scripts\AppAct.VBS"
CScript "C:\Data\Scripts\CMD_Scripts\AppAct.VBS"

Open in new window

0
 

Author Comment

by:ProTek2
ID: 34996666
Thank you both for such quick, clear responses. With only 2 minutes separating them, I'm going to split the points. Wish I had 500 for each of you.

Bottom line here is that this ole dog (started in the early 60s) needs to update his scripting tool skills. Thanks for the boot in that direction.
0
 

Author Comment

by:ProTek2
ID: 34996786
Well it looks like I got reminded that assuming is a bad idea. I ass-u-me d that the solutions would work but it turns out they don't.

I now appreciate the need to further my scripting skills even more. :-)
0
 

Author Comment

by:ProTek2
ID: 35002216
No thank you. The solutions offered failed in the same way that my previous countless attempts did. I'm approaching the whole script with vbs which I think will work and will ask another question when I've learned more about it.
0
 

Author Comment

by:ProTek2
ID: 35002309
If you, or someone else, actually knows of a solution, by all means... reopen the question. Like both of the earlier responders, I thought that making the window active would bring it to the front but that is not the case, no matter how you do it. So let's revisit it.
0
 
LVL 16

Expert Comment

by:sjklein42
ID: 35002513
I don't have a solution (yet) to this interesting problem, but the approach I am investigating is to make the window "Always-on-Top" instead of trying to "raise" it.  There does not appear to be a programmatic way to "raise" a window, but there are several utilities out there that are able to make a window become an "Alway-On-Top" window.  If anyone know how to do that from a program, speak up!
0
 
LVL 68

Expert Comment

by:Qlemo
ID: 35002564
We use the powerful and free cmdow.exe (www.commandline.co.uk/cmdow) to manipulate existing windows, e.g. resize or bring to front.
0
 

Author Comment

by:ProTek2
ID: 35002571
Because this is an install routine that has to run for novice users on XP - Win7, it has to come from normally installed functionality. I'm curious about Qlemo's comment ID 35002273 that suggested sending "...a BringToFront message to that window."
0
 

Author Comment

by:ProTek2
ID: 35002638
The /TOP option of cmdow recommended by Olemo would be perfect if it wouldn't be labeled a virus by some of the major AV vendors. Anybody have a OS function that works?
0
 
LVL 68

Expert Comment

by:Qlemo
ID: 35002810
Yes, that is a pity regarding AV. Be aware that cmdow is not classified as virus, but as Security Privacy Risk, because it can be used to hide windows from view. A SPR might be suspicious, but is not harmful in general. Nevertheless, some AV software will need to have an exception defined to let cmdow run ...

I did not try, but assume that the command window needs to be started from VBS to be able to bring it to front with AppActivate.

Maybe you could do better by using VBS only, which gives you more control over applications and windows.
0
 

Author Comment

by:ProTek2
ID: 35002849
I wouldn't be concerned about false alarms from my AV but my clients would freak out and I'd be spending all my time on the phone. :-(

So, I'm working on a purely vbs approach. The learning curve is a bit steep but I'll soon be crafting a question based on that. It would, I believe, be confusing to other readers to switch this thread to seemingly off-topic issues.
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 68

Expert Comment

by:Qlemo
ID: 35002863
Agreed. If we cannot come to a solution with the means provided, the proper course is to delete the question.
0
 

Author Comment

by:ProTek2
ID: 35002883
I'll do that now. Thanks.
0
 
LVL 14

Expert Comment

by:Psy053
ID: 35003365
Just out of curiosity, did you use the script as I provided or as markdormer provided?

0
 
LVL 16

Expert Comment

by:sjklein42
ID: 35003454
Do we really need to give up so easily?

I've been playing with the VB script posted earlier.  There were a couple of issues.  One is that it assumed a temp folder that most systems won't have, so of course that had to be changed.  The other is that the title of the target window was probably not right.

When I use this procedure with the "title" command to make sure the window has the name I expect, it seems to always work.  It also needs the "start" since without it the window only "blinks" for attention instead of coming to the front.

Change the title in both places if you change it!

title ThisIsMyWindow
echo set WSHShell = WScript.CreateObject("WScript.Shell") > "C:\temp\AppAct.VBS"
echo WSHShell.Appactivate "ThisIsMyWindow" >> "C:\temp\AppAct.VBS"
start CScript "C:\temp\AppAct.VBS"

Open in new window

0
 
LVL 14

Expert Comment

by:Psy053
ID: 35003558
Argh, I forgot to put "start" in front. Good pickup!
0
 
LVL 16

Expert Comment

by:sjklein42
ID: 35003626
Yes, the "start" was a bit of luck and inspiration.  I saw that your script worked fine when bringing other windows to the top, but when it tried to bring itself to the top it just blinked for attention.  So I figured there was some special case for when the request comes from the same process as the window.  Then I thought of using "start" to execute the VB script in another process context, and voila!

Great teamwork.

I hope this really works.  Very useful if it does.
0
 
LVL 14

Expert Comment

by:Psy053
ID: 35003717
Just for interests sake: "start" is also really usefull when calling scripts from Task Scheduler in Server 2008 (and probably W7), especially with scripts that use WSHShell.Run, and .AppActivate


0
 
LVL 16

Accepted Solution

by:
sjklein42 earned 400 total points
ID: 35004318
Fixed to use %TEMP% to point to the temp file folder instead of hard-coded folder.

title ThisIsMyWindow
echo set WSHShell = WScript.CreateObject("WScript.Shell") > "%TEMP%\AppAct.VBS"
echo WSHShell.Appactivate "ThisIsMyWindow" >> "%TEMP%\AppAct.VBS"
start CScript "%TEMP%\AppAct.VBS"

Open in new window

0
 

Author Comment

by:ProTek2
ID: 35006895
You nailed it siklein42. Both "title" and "start" are necessary for the active window to pop itself back to the front. I actually use it more than once during the install and a subsequent "start" of the previously created "activate" file works perfectly every time.

I don't have enough points available to express my full appreciation but will split them because Psy053 got it started and hung in there.

In a few minutes I'll post a seemly unrelated question about refining the setup of a new user via vbs but it's all part of this same project.

Thanks
0
 

Author Closing Comment

by:ProTek2
ID: 35006917
Thanks again
0
 
LVL 16

Expert Comment

by:sjklein42
ID: 35008239
Thanks.  Very glad it worked!  A great example of EE teamwork.
0
 

Author Comment

by:ProTek2
ID: 35008346
My relentless quest to improve prompted me to ask what is essentially a follow-up question this morning:
(ID: 26855176)
0
 

Author Comment

by:ProTek2
ID: 35008964
That is indeed good to know... definitely filed under "good stuff" :-)

Thank you VM
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Sometimes people don't understand why download speed shows differently for Windows than Linux.Specially, this article covers and shows the solution for throughput difference for Windows than a Linux machine. For this, I arranged a test scenario.I…
When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup". After a while, you have entered a loop for Auto repair which does not fix anything and you will be in a  panic as all your work w…
This Micro Tutorial will teach you how to the overview of Microsoft Security Essentials. This is a free anti-virus software that guards your PC against viruses, spyware, worms, and other malicious software. This will be demonstrated using Windows…
This Micro Tutorial will teach you how to change your appearance and customize your Windows 7 interface to your unique preference. This will be demonstrated using Windows 7 operating system.

760 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

24 Experts available now in Live!

Get 1:1 Help Now