devxlogo

How to Determine the Default Web Browser

How to Determine the Default Web Browser

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('');std::cout << browserProgram << std::endl; 

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist