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.
FrooomAsked:
Who is Participating?
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.

Rgonzo1971Commented:
Hi,

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

Regards
0
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?
0
Rgonzo1971Commented:
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

0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

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.
0
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
Loop

Open in new window

0

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?
0
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.
0
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!
0
FrooomAuthor Commented:
Exactly as needed, even has a loop for future proofing.
0
David SankovskySenior SysAdminCommented:
Don't forget to close the Question and mark helpful comments :)
Have a nice day.
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.