WinServer 2003

I need to set up a scheduled task that will open a internet explorer (in IE7) url at a specific time and close it automatically 2 minutes later.
Larry Bristersr. DeveloperAsked:
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.

Joel CoehoornDirector of Information TechnologyCommented:
This should work, but it will start the default web browser, which may not always be IE.
        Dim p As Process = Process.Start("http://www.google.com")
        If Not p.WaitForExit(120000) Then p.Kill()

Open in new window

0
Larry Bristersr. DeveloperAuthor Commented:
jcoehoorn,
Is this a vb script I open?
0
Joel CoehoornDirector of Information TechnologyCommented:
No.  Since the question is in the VS.Net and .Net Editors zones it's VB.Net code, and requires the .Net framework.  Here's a more complete listing.  Just create a new console app, replace the contents of the default Module1.vb file with this (with your desired url in the appropriate place), build it, and schedule the created .exe file for your desired time:
Module Main
    Sub Main()
        Dim p As Process = Process.Start("http://www.google.com")
        If Not p.WaitForExit(120000) Then p.Kill()
    End Sub
End Module

Open in new window

0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Larry Bristersr. DeveloperAuthor Commented:
jcoehoorn:
  Ahhhhhhhh.....

Thanks.  I'll do that.  I'm a web developer and din't think about where the answer was coming from.
0
Larry Bristersr. DeveloperAuthor Commented:
jcoehorn,
  The application(s) opened but errored on the close part.

Error message attached...
EventType clr20r3, P1 pages.exe, P2 1.0.0.0, P3 47b1f8d1, P4 pages, P5 1.0.0.0, P6 47b1f8d1, P7 11, P8 c, P9 system.nullreferenceexception, P10 NIL.
 
For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.

Open in new window

0
Joel CoehoornDirector of Information TechnologyCommented:
I did a quick check, and Process.Start() will try to re-use an existing process if possible (for example, if you already have a browser window open).  In that case, it will returns null rather than the a handle to the process used.  This code will try to grab that other process, but it's clunky in that it requires you to know in advance what your default browser is and plug that in, it requires you to have an idea what the title of the main window of the browser will be, and it will close *all* windows for that browser, including other tabs that aren't related.
Dim p As Process
p = Process.Start("http://www.google.com")
 
If p Is Nothing Then
    'need to find the process'
    Dim processes() As Process = Process.GetProcessesByName("iexplore") 'or firefox'
    For Each proc As Process In processes
        If proc.MainWindowTitle.Contains("Google") Then 'CaSe sEnsItIvE'
            p = proc
            Exit For
        End If
    Next proc
End If
 
If p IsNot Nothing AndAlso Not p.WaitForExit(120000) Then p.Kill()

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
Larry Bristersr. DeveloperAuthor Commented:
Great job.  Thanks
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
.NET Programming

From novice to tech pro — start learning today.