VB script to open IE if not already running

I am doing an OnEvent (in this case, wireless network join). The idea here is we have a specialized device that needs to go to a web page (set as home page). Occasionally the wireless drops out. As soon as it's back, my OnEvent will fire off. When it does, I want to run a  script that checks to see if internet explorer is open (URL does not matter). If it is, the script closes, otherwise it opens IE, and then closes. I'm having some trouble writing this...most of the examples I find involve specific URL's.

I wrote a basic script (it's been a loooong time since I've done any VB work), but it fails when checking to see if IE is already open.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


pls try

Set objShell = CreateObject("Shell.Application")
Set objShellWindows = objShell.Windows

If objShellWindows.Count = 0 Then
    Set Web = CreateObject("InternetExplorer.Application")
End If

Open in new window

FrooomAuthor Commented:
Hmm, doesn't work. I can't believe I didn't think to just do a count to see if it's there. However, is this looking at any open window of any application (objshell.windows), or is it looking specifically for IE?
Only the IE Windows

in vbs 

Set objShell = WScript.CreateObject("Shell.Application")
Set objShellWindows = objShell.Windows

If objShellWindows.Count = 0 Then
    Set Web = WScript.CreateObject("InternetExplorer.Application")
End If

Open in new window

Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

FrooomAuthor Commented:
Maybe I'm doing something wrong: I'm putting this code into notepad and saving as a .vbs. I then try to open/execute, but nothing happens.
David SankovskySenior SysAdminCommented:
You can try this script.

Works fine for me:

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objShell = CreateObject("Wscript.Shell")

Do While True
    Set colProcesses = objWMIService.ExecQuery _
        ("Select * from Win32_Process Where Name = 'iexplore.exe'")
    If colProcesses.Count = 0 Then
        objShell.Run "iexplore.exe"
    End If
    Wscript.Sleep 60000

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
FrooomAuthor Commented:
Alright, that worked, but I noted it keeps opening IE. I need this to only occur when my task event happens.

Example: wireless network dropped, then reconnected automatically.
OnEvent in task scheduler occurs (wireless join)
Script executes

If I remove the Do statement, as well as sleep and loop, will this simply run once, or does it need the loop?
David SankovskySenior SysAdminCommented:
The loop checks if it has been closed, and if it has it reopens it.

if you only need it to run on demand, you can remove the looping sequence.
FrooomAuthor Commented:
Never mind, I removed those portions and had it simply end if, and it seems to be doing what I need and not leaving behind copies. Thank you very much, both of you!
FrooomAuthor Commented:
Exactly as needed, even has a loop for future proofing.
David SankovskySenior SysAdminCommented:
Don't forget to close the Question and mark helpful comments :)
Have a nice day.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.