Solved

knowing the default browser

Posted on 2002-06-13
10
273 Views
Last Modified: 2010-04-04
knowing whats the default browser in my system
exe. this will return the file and the file location
 c:\program files\IEXPLORER\iexplorer.exe
0
Comment
Question by:girlswants_me
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 

Author Comment

by:girlswants_me
ID: 7074863
anybody can help me, specially this one can detect on windows XP
0
 

Author Comment

by:girlswants_me
ID: 7074888
how will i identify what kind of browser is the default ON WINDOWS XP, NOTE: as a REGULAR USER in XP.
0
 
LVL 44

Expert Comment

by:bruintje
ID: 7074950
Hi, you could take a look at this article

http://community.borland.com/article/0,1410,26083,00.html

HAGD:O)Bruintje
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Expert Comment

by:DragonSlayer
ID: 7074953
Or you can just open the registry and have a look at

HKEY_CLASSES_ROOT\http\shell\open\command
0
 
LVL 22

Accepted Solution

by:
Mohammed Nasman earned 100 total points
ID: 7075011
Hello

  use the FindExecutable API
0
 
LVL 2

Expert Comment

by:Tasomia
ID: 7075086
Hi,

Two solutions:

1)

type
  TBrowserInformation = record
    Name: string;
    Path: string;
    Version: string;
  end;

function LongPathName(ShortPathName: string): string;
var
  PIDL: PItemIDList;
  Desktop: IShellFolder;
  WidePathName: WideString;
  AnsiPathName: AnsiString;
begin
  Result := ShortPathName;
  if Succeeded(SHGetDesktopFolder(Desktop)) then
  begin
    WidePathName := ShortPathName;
    if Succeeded(Desktop.ParseDisplayName(0, nil, PWideChar(WidePathName),
      ULONG(nil^), PIDL, ULONG(nil^))) then

      try
        SetLength(AnsiPathName, MAX_PATH);
        SHGetPathFromIDList(PIDL, PChar(AnsiPathName));
        Result := PChar(AnsiPathName);

      finally
        CoTaskMemFree(PIDL);
      end;
  end;
end;

function GetDefaultBrowser: TBrowserInformation;
var
  tmp: PChar;
  res: LPTSTR;
  Version: Pointer;
  VersionInformation: Pointer;
  VersionInformationSize: Integer;
  Dummy: DWORD;
begin
  tmp := StrAlloc(255);
  res := StrAlloc(255);
  Version := nil;
  try
    GetTempPath(255, tmp);
    if FileCreate(tmp + 'htmpl.htm') <> -1 then
    begin
      if FindExecutable('htmpl.htm', tmp, res) > 32 then
      begin
        Result.Name := ExtractFileName(res);
        Result.Path := LongPathName(ExtractFilePath(res));
        // Try to determine the Browser Version
        VersionInformationSize := GetFileVersionInfoSize(Res, Dummy);
        if VersionInformationSize > 0 then
        begin
          GetMem(VersionInformation, VersionInformationSize);
          GetFileVersionInfo(Res, 0, VersionInformationSize, VersionInformation);
          VerQueryValue(VersionInformation, ('StringFileInfo040904E4ProductVersion'),
            Pointer(Version), Dummy);
          if Version <> nil then
            Result.Version := PChar(Version);
          FreeMem(VersionInformation);
        end;
      end
      else
        ShowMessage('Can''t determine the executable.');
      SysUtils.DeleteFile(tmp + 'htmpl.htm');
    end
    else
      ShowMessage('Can''t create temporary file.');
  finally
    StrDispose(tmp);
    StrDispose(res);
  end;
end;

-----------------------------------------------


2)


procedure TForm1.Button1Click(Sender: TObject);
var
  Reg: TRegistry;
  KeyName: string;
  ValueStr: string;
begin
  Reg := TRegistry.Create;
  try
    Reg.RootKey := HKEY_CLASSES_ROOT;
    KeyName  := 'htmlfile\shell\open\command';
    if Reg.OpenKey(KeyName, False) then
    begin
      ValueStr := Reg.ReadString('');
      Reg.CloseKey;
      Label1.Caption := ValueStr;
    end
    else
      ShowMessage('No Default Webbrowser !');
  finally
    Reg.Free;
  end;
end;


0
 
LVL 3

Expert Comment

by:raidos
ID: 7075140
Tasomia, note that your 2nd solution doesn't really work...

Applications should read .html\ first to get what Key to read the correct browser application...htmlfile is not used by for instance Opera...

something like this..

Function GetDefaultBrowser: String;
Var
  Reg : TRegistry;
  Browser : String;
Begin
  Result := '';
  Reg := TRegistry.Create;
  Reg.RootKey := HKEY_CLASSES_ROOT;
  If Reg.OpenKeyReadOnly('\.html') Then Begin
    Browser := Reg.ReadString('');
    Reg.CloseKey;
    If (Browser <> '') And Reg.OpenKeyReadOnly(Format('\%s\shell\open\command', [Browser])) Then Begin
      Result := Reg.ReadString('');
      If Result[1] = '"' Then Begin
        Result := Copy(Result, 2, Length(Result)-1);
        Result := Copy(Result, 1, Pos('"', Result)-1);
      End;
    End;
  End;
  Reg.CloseKey;
  Reg.Free;
End;

Regards
//raidos
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 7075171
TESTED UNDER XP PRO :

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs,Registry, StdCtrls;

const
  DEF_BROWSER = 'No Default Web Browser';


type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    function GetDefBrowser: String;
    function GetBrowserPath(AValue: String): String;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function TForm1.GetDefBrowser: String;
var
  Reg : TRegistry;
begin
  Result := '';
  Reg    := TRegistry.Create;
  try
    Reg.RootKey := HKEY_CLASSES_ROOT;
    if Reg.OpenKey('\http\shell\open\command',FALSE) then
      // '' checks the default value
      if Reg.ValueExists('') then
        // '' reads the default value
        Result := Reg.ReadString('');
    Reg.CloseKey;
  finally
    Reg.Free;
  end;
end;

function TForm1.GetBrowserPath(AValue: String): String;
var
  x      : Integer;
  tmpStr : String;
begin
  Result := DEF_BROWSER;
  if AValue = '' then
    Exit;
  // Delph strings start at 1 but we need to start past the first
  // set of quotes in the default value of the command registry
  for x := 2 to Length(AValue) do
  begin
    if AValue[x] = '"' then
      Break;
    tmpStr := tmpStr + AValue[x];
  end;

  Result := tmpStr;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  tmpStr : String;
begin
  tmpStr := GetDefBrowser();
  tmpStr := GetBrowserPath(tmpStr);
  ShowMessage(tmpStr);

end;

end.
0
 

Author Comment

by:girlswants_me
ID: 7076900
thank you everybody. well some of your code dont work on WINDOWS XP, for an ORDINARY USER. an ordinary user as you know is that the one who cannot write or read some files in the windows xp system or some directory. some other registry access are disallowed or cant be access.

So ill just used this code.. coz i already have an HTML file installed in the machine(this installed file was installed by a SUPER USER OR the Administrator which has the full access of the operating system.) when some other ORDINARY USER LOGGED in the system the user rights also change so some other userfull or important registry informations are change.

so i used this code instead

  FindExecutable(Pchar(THE_HTML_FILE),nil,Ret);
  sDefaultBrowserPath:= ExtractFilePath(Ret);
  sDefaultBrowserName:= ExtractFileName(Ret);
0
 

Author Comment

by:girlswants_me
ID: 7076903
THANK for your idea.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question