CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Guest

    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



  2. #2
    Join Date
    Jan 2000
    Posts
    27

    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




  3. #3
    Join Date
    Mar 2012
    Posts
    1

    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

  4. #4
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: How to get the default web browser path from registry?

    Dude, it's been 12 years.

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    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.
    Victor Nijegorodov

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured