Sometimes people assume that the default web browser is the program that is registered in the Windows registry to open files with an
.html extension. However, it's possible to set a default program to open
.html files and another to open URL links that use the HTTP protocol.
The code below determines the default web browser for the HTTP protocol:
DWORD size = 256; HKEY hKey; int i, pos, len;
TCHAR browserProgram[512], TCHAR buf[256];
TCHAR *exeExtension = ".exe";
RegOpenKeyEx(HKEY_CLASSES_ROOT, _TEXT("http\\shell\\open\\command"),
0, KEY_QUERY_VALUE, &hKey);
RegQueryValueEx(hKey, NULL, NULL, NULL, (LPBYTE)buf, &size);
RegCloseKey(hKey);
if (buf[0] == _TEXT('\"'))
lstrcpy(browserProgram, &buf[1]);
else
lstrcpy(browserProgram, buf);
len = lstrlen(browserProgram);
pos = len - 4;
for (i = 0; i < len - 3; i++)
if (!strnicmp(&browserProgram[i], exeExtension, 4))
{
pos = i; break;
}
browserProgram[pos + 4] = _TEXT('\0');
std::cout << browserProgram << std::endl;