Batch File Programming Help

December 28, 2010 at 21:52:38
Specs: Windows 7
I want to write a very simple batch file to open up programs like firefox or zune/itunes from within another program. I am using a program that organizes movies and it allows me to execute a file from within the program.

In order to get that to work I had to make batch files like the following:

start /max firefox.exe google.com

This opens firefox to google and works great, except for when firefox is already open. If its already opened it just opens a new instance but never switches out of the program I was originally in.

For itunes or zune it will open them in the background and keep the original program as the active window. If itunes is already opened and I execute the batch file it will then come to the forefront. That batch file is:

start /max zune.exe


Is there a command to tell the opened program to be the active window? Also is there a way to check if an instance is already running and do some sort of command depending?


See More: Batch File Programming Help

Report •


#1
December 29, 2010 at 14:52:47
I used this code for one of the post today, may be this can help.
=================================================


@echo off

echo Set WshShell = WScript.CreateObject("WScript.Shell") >temp.vbs

echo wshshell.run "Notepad" >>temp.vbs
echo wscript.sleep 1000 >>temp.vbs
echo wshshell.AppActivate "Notepad" >>temp.vbs


wscript temp.vbs


+++++++++++++++++++++++++++++++++++++

this will open up notepad and make sure Notepad will be the active window..
you can replace notepad with your program. and the 2nd line (App actiavet) you have to put the title of the program (As in title bar,few strings will work).

Subhash Chandra.


Report •

#2
December 29, 2010 at 14:55:06
tasklist gives you list of openprograms. pipe the output to find command and search for your program.
tasklist | find /i "Notepad".

if it gives a resul means the program is open.modify the batch file to execute only if the program is not running

Subhash Chandra.


Report •

#3
December 29, 2010 at 22:11:28
I used this in my batch file. It still has the same results where the other program stays on top. The media program is made to open an external program, and then when the external program is closed, it is the front window again. I don't know if that helps. I also used firefox.exe:


@echo off

echo Set WshShell = WScript.CreateObject("WScript.Shell") >temp.vbs

echo wshshell.run "Firefox" >>temp.vbs
echo wscript.sleep 1000 >>temp.vbs
echo wshshell.AppActivate "Firefox" >>temp.vbs


wscript temp.vbs


Report •

Related Solutions

#4
December 30, 2010 at 13:09:37
you should use the complete path of the Firefox exe,
I m still not sure what exactly you want, You can make any program as front program using below code, put it as and where needed.or give us a little bit more information on what exactly you want step by step, we can try to make a code.

echo wshshell.AppActivate "Firefox" >>temp.vbs

Subhash Chandra.


Report •

#5
December 30, 2010 at 13:15:26
"Is there a command to tell the opened program to be the active window?"

Nircmd.

Download nircmd: http://www.nirsoft.net/utils/nircmd...
Unzip nircmd.zip into your WINDOWS (or WINDOWS\System32) directory.

Then:

nircmd.exe win activate ititle "My Program Title"

More nircmd help? Start -> Run -> nircmd help (hit enter)

Regards,

Happy is ONE who says I am an OttoMAN.


Report •


Ask Question