How to get the default web browser path from registry?
Hi,
I'm looking for a source code to find the path of default web browser from the windows registry.
And, I want to know how to change the current URL of the browser which has been already working.
If you know how to do this, please give an answer.
Thanks.
Kilnam
Re: How to get the default web browser path from registry?
The following code
HKEY hKey;
LPCTSTR lpSubKey = _T("http\\shell\\open\\command");
RegOpenKeyEx(HKEY_CLASSES_ROOT, lpSubKey, 0L, KEY_ALL_ACCESS, &hKey);
char szValue[256];
DWORD dwSize = 256;
RegQueryValueEx(hKey, NULL, NULL, NULL, (LPBYTE)szValue, &dwSize);
will place the executable path of the default browser in szValue.
Achieving remote control of the browser is a huge subject and will depend upon which browser(s) you want to work with. In the case of Internet Explorer, I suggest you look up IWebBrowser2 in the MSDN documentation in order to get started.
Liam
Re: How to get the default web browser path from registry?
C code to get the Default Browser path from the Registry
DWORD dwBufferSize255=255;
DWORD dwBufferSize855=855;
HKEY hKey;
char szDefaultBrowserExecutableFileName[255];
char szHKEY_LOCAL_MACHINEsubkey[455];
char szDefaultBrowserPathAndExecutableFileName[855];
// first get the current Default Browser path
// use Command Prompt...regedit.... to view registry
if ( RegOpenKeyEx ( HKEY_CURRENT_USER,
"software\\clients\\StartMenuInternet",
0, // reserved
KEY_ALL_ACCESS,
&hKey)
!=
ERROR_SUCCESS )
begin
MessageBox (hwnd,
"I was unable to find a StartMenuInternet in the Registry \
\r\n Trying Internet Explorer",
"Registry ERROR.",
MB_ICONINFORMATION | MB_OK );
strcpy ( szDefaultBrowserExecutableFileName, "iexplore.exe" ); // have to try iexplore
end
else if ( RegQueryValueEx ( hKey,
NULL, // take first unnamed value name
0, // reserved
NULL, // should be REG_SZ data type, ignore
szDefaultBrowserExecutableFileName,
&dwBufferSize255)
!=
ERROR_SUCCESS )
begin
MessageBox (hwnd,
"I was unable to find a Default Browser Name in the Registry \
\r\n Trying Internet Explorer",
"Registry ERROR.",
MB_ICONINFORMATION | MB_OK );
strcpy ( szDefaultBrowserExecutableFileName, "iexplore.exe" ); // have to try iexplore
end
MessageBox ( hwnd,
szDefaultBrowserExecutableFileName,
"szDefaultBrowserExecutableFileName",
MB_ICONINFORMATION | MB_OK );
// we now know the Default Browser, next get the path
strcpy ( szHKEY_LOCAL_MACHINEsubkey, "software\\clients\\StartMenuInternet\\" );
strcat ( szHKEY_LOCAL_MACHINEsubkey, szDefaultBrowserExecutableFileName );
strcat ( szHKEY_LOCAL_MACHINEsubkey, "\\shell\\open\\command" );
MessageBox ( hwnd,
szHKEY_LOCAL_MACHINEsubkey,
"szHKEY_LOCAL_MACHINEsubkey",
MB_ICONINFORMATION | MB_OK );
if ( RegOpenKeyEx ( HKEY_LOCAL_MACHINE,
szHKEY_LOCAL_MACHINEsubkey,
0, // reserved
KEY_ALL_ACCESS,
&hKey)
!=
ERROR_SUCCESS )
begin
MessageBox (hwnd,
"I was unable to find the designated KEY_LOCAL_MACHINE \
StartMenuInternet in the Registry \
\r\n Trying C:\\Program Files\\Internet Explorer\\iexplore.exe",
"Registry ERROR.",
MB_ICONINFORMATION | MB_OK );
strcpy ( szDefaultBrowserPathAndExecutableFileName, "C:\\Program Files\\Internet Explorer\\iexplore.exe" );
end
else if ( RegQueryValueEx ( hKey,
NULL, // take first unnamed value name
0, // reserved
NULL, // should be REG_SZ data type, ignore
szDefaultBrowserPathAndExecutableFileName,
&dwBufferSize855)
!=
ERROR_SUCCESS )
begin
MessageBox (hwnd,
"I was unable to find the designated KEY_LOCAL_MACHINE \
Default Browser Path in the Registry \
\r\n Trying C:\\Program Files\\Internet Explorer\\iexplore.exe",
"Registry ERROR.",
MB_ICONINFORMATION | MB_OK );
strcpy ( szDefaultBrowserPathAndExecutableFileName, "C:\\Program Files\\Internet Explorer\\iexplore.exe" );
end
MessageBox ( hwnd,
szDefaultBrowserPathAndExecutableFileName,
"szDefaultBrowserPathAndExecutableFileName",
MB_ICONINFORMATION | MB_OK );
// we now have the Default Browser path
Re: How to get the default web browser path from registry?
Dude, it's been 12 years. :ehh:
Re: How to get the default web browser path from registry?
I agree with GCDEF.
Besides, dear tewing54, you should have first read the Announcement: Before you post.... before posting your absolutely unreadable code. :cool: