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

Need some vb6 code to set the homepage in firefox 2.0

I need to on a command1_click set the home page on firefox to "www.myhomepage.com" the code need to be in visual basic 6 .
0
newprogram
Asked:
newprogram
1 Solution
 
Shanmuga SundaramDirector of Software EngineeringCommented:
usually the homepage can be set by writing in registry

HKEY_CLASSES_ROOT\http\shell\open\command.

There are plenty of codes available in vbaccelerator.com, a1vbcode.com,programmersheaven.com to handle registry. Please check and use it to accompolish the task
0
 
newprogramAuthor Commented:
I thought firefox don't save the homepage to the registry
0
 
newprogramAuthor Commented:
will that set all webbrowsers ie,firefox , ect ?
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
advfinanceCommented:
See the following line in prefs.js file.

user_pref("browser.startup.homepage", "http://www.google.co.uk/ig");

located in the application data folder, for example:

C:\Documents and Settings\username\Application Data\Mozilla\Firefox\Profiles\random.default\prefs.js

Warning at the top of the file that edits made while firefox is running will be overwritten when it exits.
0
 
PaulHewsCommented:
Complete code.  Requires reference to Microsoft VBScript Regular Expressions 5.5
Private Sub SetFirefoxHomepage(URL As String)
    
    Dim strPath As String, strProfile As String
    Dim strContent As String, strReplace As String
    Dim regex As RegExp
    
    
    
    strPath = "C:" & Environ("HOMEPATH")
    strPath = strPath & "\Application Data\Mozilla\Firefox\Profiles\"
    strProfile = Dir(strPath & "*.default", vbDirectory)
    If Len(strProfile) Then
        Debug.Print strProfile
        strPath = strPath & strProfile & "\prefs.js"
        
        strContent = fGetFileContents(strPath)
        Set regex = New RegExp
        regex.Pattern = "user_pref\(""browser.startup.homepage"",\s""(.*)""\);"
        strReplace = "user_pref(""browser.startup.homepage"", """ & URL & """);"
        Debug.Print strReplace
        
        strContent = regex.Replace(strContent, strReplace)
        sPutStringToFile strContent, strPath
        
    End If
    
    
 
End Sub
Public Function fGetFileContents(strPath As String) As String
    Dim hFile As Integer
    Dim strFileContent As String
    
    
    If Len(Dir(strPath)) = 0 Then Exit Function
    On Error GoTo errGetFile
    hFile = FreeFile
    Open strPath For Binary As #hFile
    strFileContent = Space(LOF(hFile))
    Get #hFile, , strFileContent
    Close #hFile
    fGetFileContents = strFileContent
    Exit Function
errGetFile:
    Close
    MsgBox Err.Description, vbCritical, "GetFileContents"
    
End Function
 
Public Sub sPutStringToFile(strContent As String, strPath As String)
    Dim hFile As Integer
    
    'If file exists delete it.
    On Error Resume Next
    Kill strPath
    On Error GoTo errPutString
    
    'Write file
    hFile = FreeFile
    Open strPath For Binary As #hFile
    Put #hFile, , strContent
    Close #hFile
    
    Exit Sub
errPutString:
 
    Close
    MsgBox Err.Description, vbCritical, "PutStringToFile"
 
End Sub

Open in new window

0
 
newprogramAuthor Commented:
this is the only thing in the file for me "# Mozilla User Preferences

/* Do not edit this file.
 *
 * If you make changes to this file while the browser is running,
 * the changes will be overwritten when the browser exits.
 *
 * To make a manual change to preferences, you can visit the URL about:config
 * For more information, see http://www.mozilla.org/unix/customizing.html#prefs
 */
0
 
newprogramAuthor Commented:
how would you call it ?
SetFirefoxHomepage "http://yahoo.com"
0
 
PaulHewsCommented:
If you don't have any preferences set (from the empty preference file above) then it probably won't work.  You would have to set up some defaults.  You could write them from VB or copy a file programmatically into the profile folder.
0
 
PaulHewsCommented:
>how would you call it ?
SetFirefoxHomepage "http://yahoo.com"<

Yep.  When there are defaults already in the file.
0

Featured Post

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.

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