Results 1 to 15 of 15

Thread: [RESOLVED] [2008] Open browser on timer and specific height width

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Posts
    159

    Resolved [RESOLVED] [2008] Open browser on timer and specific height width

    Hey guys,

    I'm using kleinma's code to open a web browser after a user
    installs the software that goes to a thank you page on my
    site. I wanted to have it launch a few seconds after install
    in their default browser which is why I'm using this code below.

    I put in a timer into the form but am unfamiliar with how to
    use it specifically with kleinma's code.

    Anyone know how I can do this? And also specify the height
    and width of the page?


    vb Code:
    1. Public Sub LaunchNewBrowser(ByVal strUrl As String)
    2.         Try
    3.             'CREATE SOME VARIABLES
    4.             Dim BrowserExec As String = New String(" "c, 255)
    5.             Dim FileName As String
    6.             Dim RetVal As Long
    7.             Dim SWriter As StreamWriter
    8.             'CREATE A TEMP HTM FILE SO WE CAN FIND OUT WHAT BROWSER IS
    9.             'THE DEFAULT ONE ON THE SYSTEM
    10.             FileName = Application.StartupPath & "\temp.htm"
    11.             Try
    12.                 SWriter = File.CreateText(FileName)
    13.                 SWriter.Write("<html></html>")
    14.                 SWriter.Close()
    15.             Catch ex As Exception
    16.                 'IF ANYTHING GOES WRONG, TRY TO DO A STANDARD PROCESS LAUNCH
    17.                 BackupLaunch(strUrl)
    18.                 Return
    19.             End Try
    20.             'CALL THE API TO FIND THE EXE ASSOCIATED WITH HTM FILES
    21.             RetVal = FindExecutable(FileName, vbNullString, BrowserExec)
    22.             BrowserExec = BrowserExec.Trim
    23.             'IF WE GET ONE, LAUNCH THE URL IN THE NEW INSTANCE OF THE BROWSER
    24.             If RetVal <= 32 OrElse BrowserExec = String.Empty Then
    25.                 MessageBox.Show("Could not find a valid web browser")
    26.             Else
    27.                 Process.Start(BrowserExec, New UriBuilder(strUrl).Uri.AbsoluteUri)
    28.             End If
    29.             Try 'DELETE THAT PESKY TEMP FILE
    30.                 File.Delete(FileName)
    31.             Catch ex As Exception 'NOT GOING TO DO ANYTHING, MIGHT WANT TO LOG IT OR SOMETHING
    32.             End Try
    33.         Catch ex As Exception
    34.             'IF ANYTHING GOES WRONG, TRY TO DO A STANDARD PROCESS LAUNCH
    35.             BackupLaunch(strUrl)
    36.         End Try
    37.     End Sub
    38.     'THIS IS USED INCASE THE MAIN ROUTINE FAILS, SO WE TRY TO AT LEAST TO THE LAUNCH ANYWAY,
    39.     'EVEN THOUGH IT WILL BE IN AN ALREADY OPEN WINDOW. ITS A SECOND SUB BC ITS USED MORE THAN
    40.     'ONCE IN THE MAIN ROUTINE
    41.     Private Sub BackupLaunch(ByVal strURL As String)
    42.         Try
    43.             Process.Start(strURL)
    44.         Catch ex As Exception
    45.             MessageBox.Show("Could not launch website. Error Unknown.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
    46.         End Try
    47.     End Sub
    48.  
    49. End Module

    Chris

  2. #2
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    Re: [2008] Open browser on timer and specific height width

    Couldnt you just do Process.Start()?

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Posts
    159

    Re: [2008] Open browser on timer and specific height width

    No. Process start doesn't open the default web browser
    and it throws errors unless there is already a browser opened.

  4. #4
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    Re: [2008] Open browser on timer and specific height width

    Quote Originally Posted by cmmorris1
    No. Process start doesn't open the default web browser
    and it throws errors unless there is already a browser opened.
    I am not sure about the first thing you said. But about the errors, no it opens the browser for you.

    I always thought it opens your default browser... e.g.

    Process.Start("http://www.google.com")

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Posts
    159

    Re: [2008] Open browser on timer and specific height width

    nope, if you use it and no browsers are open you get a
    nice little error box that pops up. this is much cleaner anyhow
    if I can figure out how to set it on a timer to launch the
    browser and if I can set the width / height of the window
    that would be even better.

  6. #6
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    Re: [2008] Open browser on timer and specific height width

    I get no errors... i always use Process.Start to open a website.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Posts
    159

    Re: [2008] Open browser on timer and specific height width

    I get errors on Vista which is why I started using his
    code for this, now if I can figure out how to use the
    timer event to launch the procedure I'd be a happy
    camper.

  8. #8
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    Re: [2008] Open browser on timer and specific height width

    Oh ok, i am using XP, process.start works fine on xp.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Posts
    159

    Re: [2008] Open browser on timer and specific height width

    You don't know how to use a timer for calling this?

  10. #10
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    Re: [2008] Open browser on timer and specific height width

    In the Timer tick event you would place LaunchNewBrowser(..website..)

    What do you need help with? about your timer?

    Do you know how to use a timer in the first place?

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Posts
    159

    Re: [2008] Open browser on timer and specific height width

    Yeah, I do from examples I've looked over.
    Seems like it still isn't clear to me how to put
    it together for this though.

    I've put timer1.enabled = true in the form load
    and in the timer tick event I have BrowserExec.LaunchNewBrowser("http://mysite.com/")

    You need to use BrowserExec.LaunchNewBrowser("url")
    but it's getting it to wait a few seconds that I can't
    figure out.

  12. #12
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    Re: [2008] Open browser on timer and specific height width

    What do you have the interval set to?
    What do you need it set to?

    With a timer you need to set the interval before you enable the timer.

    Code:
    Timer1.Interval = 1000
    Timer1.Enabled = True
    The above sets a Timer called Timer one, the Tick event will be initiated after 1 second (1000)

    1000 = 1 second
    2000 = 2 seconds etc...

    EDIT: Why do you want to use the timer in the first place?

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Posts
    159

    Re: [2008] Open browser on timer and specific height width

    I'm using a timer to wait for a few seconds once the user
    has installed the software and opened up for the first time
    to display a quick thank you note. I could do without it but
    it I thought that if I wait a little bit after they open it up before
    it launches it won't seem so annoying I guess.

    Thank you for your help! It's finally working correctly!

    Chris

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Posts
    159

    [2008] Open browser on timer and specific height width

    Forgot to ask what can I use to set the width and height of
    the window?

  15. #15
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    Re: [RESOLVED] [2008] Open browser on timer and specific height width

    Also remember to rate me if I helped. About the width & height I will get back to you on that later today I am in a rush now.
    Last edited by noahssite; Jan 16th, 2010 at 04:16 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width