Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 276
  • Last Modified:

knowing the default browser

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
girlswants_me
Asked:
girlswants_me
1 Solution
 
girlswants_meAuthor Commented:
anybody can help me, specially this one can detect on windows XP
0
 
girlswants_meAuthor Commented:
how will i identify what kind of browser is the default ON WINDOWS XP, NOTE: as a REGULAR USER in XP.
0
 
bruintjeCommented:
Hi, you could take a look at this article

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

HAGD:O)Bruintje
0
Industry Leaders: 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!

 
DragonSlayerCommented:
Or you can just open the registry and have a look at

HKEY_CLASSES_ROOT\http\shell\open\command
0
 
Mohammed NasmanSoftware DeveloperCommented:
Hello

  use the FindExecutable API
0
 
TasomiaCommented:
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
 
raidosCommented:
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
 
ginsonicCommented:
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
 
girlswants_meAuthor Commented:
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
 
girlswants_meAuthor Commented:
THANK for your idea.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now