Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Set My Browser As The Default Browser

16 views
Skip to first unread message

RN1

unread,
Dec 29, 2007, 8:27:42 AM12/29/07
to
I have created a web browser using the WebBrowser control in VB6. I
would like to set this browser as the default browser in the user's
machine. This is how I tried it:

*******Module Code***********

Private Declare Function RegCreateKey Lib "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
*****************************

********Form Code*********

Public Sub cmdDefault_Click()
'AssociateMyApp is a function in the module
AssociateMyApp "MyBrowser", """" & App.Path & "\" & App.EXEName &
".exe"" %1", "html", "", "" & App.Path & "\IMAGES\MyBrowser.ico"

SetRegKey HKEY_CLASSES_ROOT, "ftp\DefaultIcon", "", App.Path &
"\IMAGES\MyBrowser.ico"
SetRegKey HKEY_CLASSES_ROOT, "ftp\shell\open\command", "", """" &
App.Path & "\" & App.EXEName & ".exe"" %1"
SetRegKey HKEY_CLASSES_ROOT, "ftp\shell\open\ddeexec", "", "%1"
SetRegKey HKEY_CLASSES_ROOT, "ftp\shell\open\ddeexec\Application",
"", "MyBrowser"
SetRegKey HKEY_CLASSES_ROOT, "ftp\shell\open\ddeexec\Topic", "",
"frmMyBrowser"

SetRegKey HKEY_CLASSES_ROOT, "htmlfile\DefaultIcon", "", App.Path
& "\IMAGES\MyBrowser.ico"
SetRegKey HKEY_CLASSES_ROOT, "htmlfile\shell\open\command", "",
"""" & App.Path & "\" & App.EXEName & ".exe"" %1"
SetRegKey HKEY_CLASSES_ROOT, "htmlfile\shell\open\ddeexec", "",
"%1"
SetRegKey HKEY_CLASSES_ROOT, "htmlfile\shell\open\ddeexec
\Application", "", "MyBrowser"
SetRegKey HKEY_CLASSES_ROOT, "htmlfile\shell\open\ddeexec\Topic",
"", "frmMyBrowser"
SetRegKey HKEY_CLASSES_ROOT, "htmlfile\shell\opennew\command", "",
"""" & App.Path & "\" & App.EXEName & ".exe"" %1"
SetRegKey HKEY_CLASSES_ROOT, "htmlfile\shell\opennew\ddeexec", "",
"%1"
SetRegKey HKEY_CLASSES_ROOT, "htmlfile\shell\opennew\ddeexec
\Application", "", "MyBrowser"
SetRegKey HKEY_CLASSES_ROOT, "htmlfile\shell\opennew\ddeexec
\Topic", "", "frmMyBrowser"

SetRegKey HKEY_CLASSES_ROOT, "http\DefaultIcon", "", App.Path &
"\IMAGES\MyBrowser.ico"
SetRegKey HKEY_CLASSES_ROOT, "http\shell\open\command", "", """" &
App.Path & "\" & App.EXEName & ".exe"" %1"
SetRegKey HKEY_CLASSES_ROOT, "http\shell\open\ddeexec", "", "%1"
SetRegKey HKEY_CLASSES_ROOT, "http\shell\open\ddeexec
\Application", "", "MyBrowser"
SetRegKey HKEY_CLASSES_ROOT, "http\shell\open\ddeexec\Topic", "",
"frmMyBrowser"

SetRegKey HKEY_CLASSES_ROOT, "https\DefaultIcon", "", App.Path &
"\IMAGES\MyBrowser.ico"
SetRegKey HKEY_CLASSES_ROOT, "https\shell\open\command", "", """"
& App.Path & "\" & App.EXEName & ".exe"" %1"
SetRegKey HKEY_CLASSES_ROOT, "https\shell\open\ddeexec", "", "%1"
SetRegKey HKEY_CLASSES_ROOT, "https\shell\open\ddeexec
\Application", "", "MyBrowser"
SetRegKey HKEY_CLASSES_ROOT, "https\shell\open\ddeexec\Topic", "",
"frmMyBrowser"

RegCreateKey &H80000000, "MyBrowser.HTML\DefaultIcon", 0
RegCreateKey &H80000000, "MyBrowser.HTML\shell\open\command", 0
Registry_Write "HKEY_CLASSES_ROOT\MyBrowser.HTML\DefaultIcon\",
"", """" & App.Path & "\IMAGES\MyBrowser.ico"""
Registry_Write "HKEY_CLASSES_ROOT\MyBrowser.HTML\DefaultIcon\",
"", "" & App.Path & "\IMAGES\MyBrowser.ico"
Registry_Write "HKEY_CLASSES_ROOT\MyBrowser.HTML\shell\", "",
"Open", "REG_SZ"
Registry_Write "HKEY_CLASSES_ROOT\MyBrowser.HTML\shell\open\", "",
"Open With MyBrowser", "REG_SZ"
Registry_Write "HKEY_CLASSES_ROOT\MyBrowser.HTML\shell\open\command
\", "", """" & 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_MACHINE\Software\Classes\Applications
\MyBrowser.exe\shell\", "FriendlyCache", "MyBrowser", "REG_SZ"
Registry_Write "HKEY_CLASSES_ROOT\Applications\MyBrowser.exe\shell
\", "FriendlyCache", "MyBrowser", "REG_SZ"
End Sub
*****************************

When I double-click a HTML file in Windows Explorer, then instead of
opening in my browser, the HTML file opens in IE6 but if I right-click
a HTML file, navigate to "Open With" & then select my browser from the
context menu, then the HTML file opens in my browser.

Can someone please tell me why aren't HTML files opening in my browser
but instead opening in my IE when I double-click them? Where am I
erring?

0 new messages