• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 179
  • Last Modified:

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.
0
lrbrister
Asked:
lrbrister
  • 4
  • 3
1 Solution
 
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
 
lrbristerAuthor 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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
lrbristerAuthor 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
 
lrbristerAuthor 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
 
lrbristerAuthor Commented:
Great job.  Thanks
0

Featured Post

2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now