Set My Browser As The Default Browser - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Set My Browser As The Default Browser

rn5arn5a Posts: 1Member
I have created a web browser in VB6 using the web browser control. I have set it as the default browser but when I double click a HTML file in Windows Explorer, the HTML file doesn't open in my browser; rather it opens in IE6 but if I right-click the HTML file, navigate to [italic]Open With[/italic] & then select my browser from the context menu, the HTML file opens in my browser.

Can someone PLEASE help me resolve this issue? I have made the necessary changes in the registry but don't know why HTML files don't open in my browser when I double click them & instead open in IE. Note that the icon of HTML files change to what I have assigned in my app. This is the code:

[u][b]MODULE CODE[/b][/u]:[code]Private Declare Function RegCreateKey ib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long

Public Function SetRegKey(KeyRoot As RegistryRoot, KeyName As String, ValueName As String, ValueData As Variant) As Boolean
Dim strValueData As String
strValueData = CStr(ValueData)
SetRegKey = REGTool5.UpdateKey(KeyRoot, KeyName, ValueName, strValueData)
ValueData = strValueData
End Function

Public Sub AssociateMyApp(ByVal sAppName As String, ByVal sEXE As String, ByVal sExt As String, Optional ByVal sCommand As String, Optional ByVal sIcon As String)
Dim lRegKey As Long
Dim sCommandString As String

'open/create the extension under the "HKEY_CLASSES_ROOT" hive of the Registry
Call RegCreateKey(HKEY_CLASSES_ROOT, "." & sExt, lRegKey)

'set the "Default" value of the key to the app/EXE name
Call RegSetValueEx(lRegKey, "", 0&, 1, ByVal sAppName, Len(sAppName))

'close the Registry key
Call RegCloseKey(lRegKey)

sCommand = "Shell" & IIf(Len(sCommand), sCommand, "Open") & "Command"

'create the app key in the "HKEY_CLASSES_ROOT" hive of the Registry
Call RegCreateKey(HKEY_CLASSES_ROOT, sAppName & sCommand, lRegKey)

'set the command to the EXE
Call RegSetValueEx(lRegKey, "", 0&, 1, ByVal sEXE, Len(sEXE))

'close the Registry key
Call RegCloseKey(lRegKey)

'if an icon is required...
If (Len(sIcon)) Then
'create a "DefaultIcon"
Call RegCreateKey(HKEY_CLASSES_ROOT, sAppName & "DefaultIcon", lRegKey)

Call RegSetValueEx(lRegKey, "", 0&, 1, ByVal sIcon, Len(sIcon))
Call RegCloseKey(lRegKey)
End If

'notify the Shell that an association has changed, (updates icons)
SHChangeNotify SHCNE_ASSOCCHANGED, SHCNF_IDLIST, vbNullString, vbNullString
End Sub

Public Sub Registry_Write(Key_Path As String, Key_Name As String, Key_Value As Variant, Optional Key_Type As String)
Dim Registry As Object
Dim Registry_Value As Variant

Set Registry = CreateObject("WScript.Shell")
If (Key_Type = "") Then
Registry.RegWrite Key_Path & Key_Name, Key_Value
Else
Registry.RegWrite Key_Path & Key_Name, Key_Value, Key_Type
End If
End Sub[/code]
[b]FORM CODE[/b][u][/u]:[code]Public Sub cmdDefault_Click()
'AssociateMyApp is the function in the above module
AssociateMyApp "MyBrowser", """" & App.Path & "" & App.EXEName & ".exe"" %1", "html", "", "" & App.Path & "IMAGESMyBrowser.ico"

SetRegKey HKEY_CLASSES_ROOT, "ftpDefaultIcon", "", App.Path & "IMAGESMyBrowser.ico"
SetRegKey HKEY_CLASSES_ROOT, "ftpshellopencommand", "", """" & App.Path & "" & App.EXEName & ".exe"" %1"
SetRegKey HKEY_CLASSES_ROOT, "ftpshellopenddeexec", "", "%1"
SetRegKey HKEY_CLASSES_ROOT, "ftpshellopennewddeexecApplication", "", "MyBrowser"
SetRegKey HKEY_CLASSES_ROOT, "ftpshellopenddeexecTopic", "", "frmMyBrowser"

SetRegKey HKEY_CLASSES_ROOT, "htmlfileDefaultIcon", "", App.Path & "IMAGESMyBrowser.ico"
SetRegKey HKEY_CLASSES_ROOT, "htmlfileshellopencommand", "", """" & App.Path & "" & App.EXEName & ".exe"" %1"
SetRegKey HKEY_CLASSES_ROOT, "htmlfileshellopenddeexec", "", "%1"
SetRegKey HKEY_CLASSES_ROOT, "htmlfileshellopenddeexecApplication", "", "MyBrowser"
SetRegKey HKEY_CLASSES_ROOT, "htmlfileshellopenddeexecTopic", "", "frmMyBrowser"

SetRegKey HKEY_CLASSES_ROOT, "htmlfileshellopennewcommand", "", """" & App.Path & "" & App.EXEName & ".exe"" %1"
SetRegKey HKEY_CLASSES_ROOT, "htmlfileshellopennewddeexec", "", "%1"
SetRegKey HKEY_CLASSES_ROOT, "htmlfileshellopennewddeexecApplication", "", "MyBrowser"
SetRegKey HKEY_CLASSES_ROOT, "htmlfileshellopennewddeexecTopic", "", "frmMyBrowser"

SetRegKey HKEY_CLASSES_ROOT, "httpDefaultIcon", "", App.Path & "IMAGESMyBrowser.ico"
SetRegKey HKEY_CLASSES_ROOT, "httpshellopencommand", "", """" & App.Path & "" & App.EXEName & ".exe"" %1"
SetRegKey HKEY_CLASSES_ROOT, "httpshellopenddeexec", "", "%1"
SetRegKey HKEY_CLASSES_ROOT, "httpshellopenddeexecApplication", "", "MyBrowser"
SetRegKey HKEY_CLASSES_ROOT, "httpshellopenddeexecTopic", "", "frmMyBrowser"

SetRegKey HKEY_CLASSES_ROOT, "httpsDefaultIcon", "", App.Path & "IMAGESMyBrowser.ico"
SetRegKey HKEY_CLASSES_ROOT, "httpsshellopencommand", "", """" & App.Path & "" & App.EXEName & ".exe"" %1"
SetRegKey HKEY_CLASSES_ROOT, "httpsshellopenddeexec", "", "%1"
SetRegKey HKEY_CLASSES_ROOT, "httpsshellopenddeexecApplication", "", "MyBrowser"
SetRegKey HKEY_CLASSES_ROOT, "httpsshellopenddeexecTopic", "", "frmMyBrowser"

RegCreateKey &H80000000, "MyBrowser.HTMLDefaultIcon", 0
RegCreateKey &H80000000, "MyBrowser.HTMLshellopencommand", 0
Registry_Write "HKEY_CLASSES_ROOTMyBrowser.HTMLDefaultIcon", "", """" & App.Path & "IMAGESMyBrowser.ico"""
Registry_Write "HKEY_CLASSES_ROOTMyBrowser.HTMLDefaultIcon", "", "" & App.Path & "IMAGESMyBrowser.ico"
Registry_Write "HKEY_CLASSES_ROOTMyBrowser.HTMLshell", "", "Open", "REG_SZ"
Registry_Write "HKEY_CLASSES_ROOTMyBrowser.HTMLshellopen", "", "Open With MyBrowser", "REG_SZ"
Registry_Write "HKEY_CLASSES_ROOTMyBrowser.HTMLshellopencommand", "", """" & App.Path & "" & App.EXEName & ".exe"" %1", "REG_SZ"
Registry_Write "HKEY_CLASSES_ROOT.htm", "", "MyBrowser.HTML", "REG_SZ"
Registry_Write "HKEY_CLASSES_ROOT.html", "", "MyBrowser.HTML", "REG_SZ"
Registry_Write "HKEY_LOCAL_MACHINESoftwareClassesApplicationsMyBrowser.exeshell", "FriendlyCache", "MyBrowser", "REG_SZ"
Registry_Write "HKEY_CLASSES_ROOTApplicationsMyBrowser.exeshell", "FriendlyCache", "MyBrowser", "REG_SZ"
End Sub[/code]
What I find surprising is till yesterday, the above code was working fine & double clicking HTML files used to open in my browser but today I find that they open in IE & not in my browser when I set my browser as the default browser.
Sign In or Register to comment.