[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:
Public Sub LaunchNewBrowser(ByVal strUrl As String)
Try
'CREATE SOME VARIABLES
Dim BrowserExec As String = New String(" "c, 255)
Dim FileName As String
Dim RetVal As Long
Dim SWriter As StreamWriter
'CREATE A TEMP HTM FILE SO WE CAN FIND OUT WHAT BROWSER IS
'THE DEFAULT ONE ON THE SYSTEM
FileName = Application.StartupPath & "\temp.htm"
Try
SWriter = File.CreateText(FileName)
SWriter.Write("<html></html>")
SWriter.Close()
Catch ex As Exception
'IF ANYTHING GOES WRONG, TRY TO DO A STANDARD PROCESS LAUNCH
BackupLaunch(strUrl)
Return
End Try
'CALL THE API TO FIND THE EXE ASSOCIATED WITH HTM FILES
RetVal = FindExecutable(FileName, vbNullString, BrowserExec)
BrowserExec = BrowserExec.Trim
'IF WE GET ONE, LAUNCH THE URL IN THE NEW INSTANCE OF THE BROWSER
If RetVal <= 32 OrElse BrowserExec = String.Empty Then
MessageBox.Show("Could not find a valid web browser")
Else
Process.Start(BrowserExec, New UriBuilder(strUrl).Uri.AbsoluteUri)
End If
Try 'DELETE THAT PESKY TEMP FILE
File.Delete(FileName)
Catch ex As Exception 'NOT GOING TO DO ANYTHING, MIGHT WANT TO LOG IT OR SOMETHING
End Try
Catch ex As Exception
'IF ANYTHING GOES WRONG, TRY TO DO A STANDARD PROCESS LAUNCH
BackupLaunch(strUrl)
End Try
End Sub
'THIS IS USED INCASE THE MAIN ROUTINE FAILS, SO WE TRY TO AT LEAST TO THE LAUNCH ANYWAY,
'EVEN THOUGH IT WILL BE IN AN ALREADY OPEN WINDOW. ITS A SECOND SUB BC ITS USED MORE THAN
'ONCE IN THE MAIN ROUTINE
Private Sub BackupLaunch(ByVal strURL As String)
Try
Process.Start(strURL)
Catch ex As Exception
MessageBox.Show("Could not launch website. Error Unknown.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
End Module
Chris
Re: [2008] Open browser on timer and specific height width
Couldnt you just do Process.Start()?
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.
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")
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.
Re: [2008] Open browser on timer and specific height width
I get no errors... i always use Process.Start to open a website.
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.
Re: [2008] Open browser on timer and specific height width
Oh ok, i am using XP, process.start works fine on xp.
Re: [2008] Open browser on timer and specific height width
You don't know how to use a timer for calling this?
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?
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.
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?
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
[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?
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.