Thread: How Can I Find the Default Browser?

  1. #1
    Arggggh DeepFyre's Avatar
    Join Date
    Sep 2004
    Posts
    227

    How Can I Find the Default Browser?

    just wondering how i could find the default browser in windows. im runnin xp home fyi.

    thanks for any help in advance.
    Keyboard Not Found! Press any key to continue. . .

  2. #2
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905
    By doing some research, I found that the exe is pointed to by the following registry key:

    HKEY_CLASSES_ROOT\http\shell\open\command\default

    Searched:
    default browser win32

    Got the following link:
    http://www.jniwrapper.com/docs/javad...wserPaths.html

  3. #3
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    You can save some leg work by getting AssocQueryString to search the registry for you.
    Code:
    #include <windows.h>
    #include <shlwapi.h>
    #include <stdio.h>
    
    #if defined (_MSC_VER)
    #pragma comment(lib, "shlwapi.lib")
    #elif defined (__LCC__)
    #pragma lib<shlwapi.lib>
    #endif
    
    #define ARRAY_SIZE(arr) (sizeof(arr)/sizeof((arr)[0]))
    
    int main(void)
    {
    	HRESULT hr;
    	TCHAR szExe[MAX_PATH + 100];
    	DWORD cchExe = ARRAY_SIZE(szExe);
    
    	if (SUCCEEDED(hr = AssocQueryString(0, ASSOCSTR_EXECUTABLE,
    	                                    TEXT("http"), TEXT("open"), szExe, &cchExe)))
    	{
    		printf("Path to default browser is '%s'.\n", szExe);
    	}
    	else
    	{
    		printf("Failed with error 0x%08.8x.", hr);
    	}
    
    	getchar();
    	return 0;
    }
    Note: In my version of Dev-C++/Mingw, there is an error in shlwapi.h that will cause this code to give incorrect results. Lines 60-63 are:
    Code:
    typedef enum {
        ASSOCSTR_COMMAND,
        ASSOCSTR_EXECUTABLE,
        ASSOCSTR_FRIENDLYDOCNAME,
    instead of:
    Code:
    typedef enum {
        ASSOCSTR_COMMAND      = 1, 
        ASSOCSTR_EXECUTABLE,
        ASSOCSTR_FRIENDLYDOCNAME,
    Last edited by anonytmouse; 02-12-2005 at 08:00 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. spawn default html browser
    By odysseus.lost in forum C Programming
    Replies: 6
    Last Post: 11-11-2005, 12:27 PM
  2. Open default browser and send an HTTP request (POST Method)
    By dit6a9 in forum Windows Programming
    Replies: 3
    Last Post: 09-03-2005, 01:31 AM
  3. Launching the default browser
    By darkknight1984 in forum C++ Programming
    Replies: 4
    Last Post: 06-10-2005, 08:43 AM
  4. Default Constructors w/Classes as Parameters
    By GrNxxDaY in forum C++ Programming
    Replies: 22
    Last Post: 07-31-2002, 07:50 AM
  5. Switching Default Buttons :: MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 07-02-2002, 04:08 PM