Solved

Make an active batch file window visible after starting browser

Posted on 2011-02-27
30
750 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
[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
  • 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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 

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 69

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 69

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
 
LVL 69

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows XP and a 3TB drive that Windows cannot see 19 82
SharpDesk V3.3 Scanning Issue 7 18
Windows 7 usb repair boot 16 51
Delete Temp on all PCs 7 51
New Windows 7 Installations take days for Windows-Updates to show up and install. This can easily be fixed. I have finally decided to write an article because this seems to get asked several times a day lately. This Article and the Links apply to…
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

733 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