Solved I need a loop

August 1, 2012 at 10:02:48
Specs: Windows XP
I need a loop that works in windows xp, windows 7 and vista. I need to run Internet explorer and Firefox on a timed interval to switch back and forth any help creating a Autoit or notepad loop to perform this task would be greatly appreciated. I know hardly anything about coding, Please Help this is what i have but it only works in Windows XP

' Define the titles to look for
gTitle1 = "notepad"
gTitle2 = "explorer"
gSecondsToWait = 10

' If one of the window closes, this variable becomes False and the script exits.
Dim bWindowFound

' Create scripting object
Dim WShell, lRunUninstall
Set WShell = CreateObject("WScript.Shell")

Do
' Activate the window that has a title matching, starting, or ending with gTitle1.
bWindowFound = WShell.AppActivate(gTitle1)

' Check if we activated the window ?
If(bWindowFound) Then

' Send ALT+SPACEBAR (system menu) M (move) ESCAPE (cancel) to activate window.
WShell.SendKeys "% M{ESCAPE}"

' Wait 10 seconds
WScript.Sleep (gSecondsToWait * 1000)

' You can either send ALT+TAB and then wait 60 seconds, or activate the other window
'WShell.SendKeys "%{TAB}"

' Switch to the other window
bWindowFound = WShell.AppActivate(gTitle2)
If(bWindowFound) Then

' Send ALT+SPACEBAR (system menu) M (move) ESCAPE (cancel) to activate window.
WShell.SendKeys "% M{ESCAPE}"

' Wait 10 seconds
WScript.Sleep (gSecondsToWait * 1000)
End If
End If

Loop Until Not bWindowFound

' Completed. Stop the script
WScript.Echo "Quitting script"
Set WShell = Nothing
WScript.quit(0)


See More: I need a loop

Report •

✔ Best Answer
August 2, 2012 at 08:51:35
I'm unsure of what problem you're attempting to solve, but it sounds like it might be easier to use Firefox with IE Tab, and some tab rotator plugin.

How To Ask Questions The Smart Way



#1
August 1, 2012 at 23:35:36
Well, for one thing, I think your information about appactivate is incorrect. It will not activate window title "post", only "pre". So, if for example, as i just tested, using internet explorer in this post, the "title" is "i need a loop". Tried to find "internet explorer"? No joy! Look for "I need": ok. Might be diff.s between windows versions, but doubtful.
With some work, you can use tasklist to refine your targets, especially using Process Id instead of window title (any b---tard batch can title its window using "title", and you have no idea what IE or firefox or whoever might put into the title-bar.). That comes back to the tasklist, which really rules. Then, you might have a dozen instances of IE running... Then, you have to know which one to kill, or switch to, or send keys into.
It is doable. just not as easy, i suspect, as you first suspecteed.

Report •

#2
August 2, 2012 at 07:45:21
Thank you for your reply, this file works for windows xp i've tested it multiple times you use the process name in the two titles so for example

gTitle1 = "firefox"
gTitle2 = "explorer"
gSecondsToWait = 10

this is what I need to alternate and this works in xp ive tested it as well

What im asking is if anyone has a simpler batch file or program, I just need to alternate between firefox and internet explorer on a timed interval that will work in all three Windows platforms, XP, Windows 7, and Vista. I will be monitoring this computer and it is for a display board that will only have firefox and internet explorer running. Im open to other suggestions as well. I have a very very basic knowledge of how this all works so as much help as possible is greatly appreciated because I'm limited to what little i know about this type of thing.


Report •

#3
August 2, 2012 at 07:48:42
also i've created this as well and saved it as runscript.cmd I Apologize for leaving this out to begin with

@ECHO OFF
@ECHO.
@ECHO Running script to switch between two windows
@ECHO.

CScript //nologo switch.vbs

@ECHO.
@ECHO Script completed.
@ECHO.


Report •

Related Solutions

#4
August 2, 2012 at 08:51:35
✔ Best Answer
I'm unsure of what problem you're attempting to solve, but it sounds like it might be easier to use Firefox with IE Tab, and some tab rotator plugin.

How To Ask Questions The Smart Way


Report •

#5
August 2, 2012 at 09:27:06
I need something a program or batch file to run and switch between two windows continously on a timed interval the two windows are "firefox" and "internet explorer" and it has to work with windows 7, xp, and vista



Report •

#6
August 2, 2012 at 09:41:36
That is not the problem. That's the solution you've decided on, but don't know how to reach.

How To Ask Questions The Smart Way


Report •

#7
August 2, 2012 at 18:24:54
My apologies. You're correct and I am wrong. I SWEAR I tested, but maybe I was on the old ME machine, i don't know. Anyway, your script WILL find the window. That said, not sure where you are having problems... looks like you got everthing working. Where is it failing?
I believe you don't need to send any keys into these windows, just activate usiing
"window-style" set to 1:
test=appactivate("notepad",1)
I don't think you need to do the alt-M or alt spacebar with ESC. Window should
maximize on activation without sending anything into it.
Looks to me like you got'er whipped, but if not, what type of error or failure?
PS: I have a vista, somewhere, but can't find it off hand to test. I got seven and xp available to test, if you need more help. What you got looks like it should work.

Report •

#8
August 4, 2012 at 05:42:47
I can't get it to run on vista or windows 7 and I dont know why it wont work nbrane, I double click it and nothing happens

Report •

Ask Question