• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 194
  • Last Modified:

How to detect if internet and a browser is installed?

I write at a program in Delphi 3 that will use a TLABEL as link to a website. It gets the ONCLICK-Event and should start the browser with the URL defined in .CAPTION. I know that IE4 can connect to an URL given thru the command line as parameter. But first, how would i check, if IE or NS or any other browser and a internet-access software is installed on the computer that runs my program on :)

thx, Omsec
0
omsec
Asked:
omsec
1 Solution
 
JaccoCommented:
You can try

ShellExecute('http:\\www.microsoft.com');

this way you execute a URL

Internet explorer is started automatically

No command line needed.

To determine wether IE is installed you can check the proper registryentries !
0
 
omsecAuthor Commented:
do I have to include a special (Active-X) Control/Unit ?
0
 
dskowronCommented:
Delphi 3 includes native controls for web programming so there would be no need for any Active X or other outside control. However, the comment made by Jacco is correct - you just execute the url. The "HTM" or "HTML" file extension would be registered to be handled by the user's browser. If none existed, you could trap that error. Actually, in that case, you could launch a simple browser that you write in Delphi 3.
0
 
omsecAuthor Commented:
ShellExecute('http:\\www.microsoft.com'); does not work
0
 
Holger101497Commented:
I'm afraid it is a little more complicated than this....
Try to take a look at the Delphi FAQ at http://www.inprise.com/devsupport/delphi/qanda/#9

This is for How to launch web site in default browser:

Frequently Asked Questions

                       Displaying documents in the default browser

                       Question:

                       How can I start the default browser with an URL in a new browser window?

                       Answer:

                       The following example attempts to start the specified URL
                       in a new browser window. Note: Not all versions of
                       Internet Explorer will respond with a new window.

                       Example:

                       uses
                        DdeMan,
                       {$IFDEF WIN32}
                         Registry; {We will get it from the registry}
                       {$ELSE}
                         IniFiles; {We will get it from the win.ini file}
                       {$ENDIF}

                       {$IFNDEF WIN32}
                         const MAX_PATH = 144;
                       {$ENDIF}

                       function GetProgramAssociation (Ext : string) : string;
                       var
                       {$IFDEF WIN32}
                         reg: TRegistry;
                         s : string;
                       {$ELSE}
                         WinIni : TIniFile;
                         WinIniFileName : array[0..MAX_PATH] of char;
                         s : string;
                       {$ENDIF}
                       begin
                       {$IFDEF WIN32}
                         s := '';
                         reg := TRegistry.Create;
                         reg.RootKey := HKEY_CLASSES_ROOT;
                         if reg.OpenKey('.' + ext + '\shell\open\command',
                                        false) <> false then begin
                         {The open command has been found}
                           s := reg.ReadString('');
                           reg.CloseKey;
                         end else begin
                         {perhaps thier is a system file pointer}
                           if reg.OpenKey('.' + ext,
                                          false) <> false then begin
                             s := reg.ReadString('');
                             reg.CloseKey;
                             if s <> '' then begin
                            {A system file pointer was found}
                               if reg.OpenKey(s + '\shell\open\command',
                                              false) <> false then
                            {The open command has been found}
                                 s := reg.ReadString('');
                               reg.CloseKey;
                             end;
                           end;
                         end;
                        {Delete any command line, quotes and spaces}
                         if Pos('%', s) > 0 then
                           Delete(s, Pos('%', s), length(s));
                         if ((length(s) > 0) and
                             (s[1] = '"')) then
                           Delete(s, 1, 1);
                         if ((length(s) > 0) and
                             (pos('"', s) > 0)) then
                           Delete(s, pos('"', s), Length(s));
                         while ((length(s) > 0) and
                                (s[length(s)] = #32)) do
                           Delete(s, Length(s), 1);
                       {$ELSE}
                         GetWindowsDirectory(WinIniFileName, sizeof(WinIniFileName));
                         StrCat(WinIniFileName, '\win.ini');
                         WinIni := TIniFile.Create(WinIniFileName);
                         s := WinIni.ReadString('Extensions',
                                                 ext,
                                                 '');
                         WinIni.Free;
                        {Delete any command line}
                         if Pos(' ^', s) > 0 then
                           Delete(s, Pos(' ^', s), length(s));
                        {$ENDIF}
                         result := s;
                       end;

                       procedure StartNewBrowserWindow(URL : string);
                       var
                         DDEConv : TDDEClientConv;
                         URLFired : bool;
                         App : string;
                         UpApp : string;
                         p : array[0..MAX_PATH] of char;
                       begin
                         UrlFired := false;
                         App := GetProgramAssociation('HTM');
                         UpApp := Uppercase(App);
                         Delete(App, Pos('.EXE', UpAPP), length(App));
                         if Pos('NETSCAPE.EXE',
                                UpApp) > 0 then begin
                           DDEConv:=TDDEClientConv.Create(nil);
                           DDEConv.ServiceApplication := App;
                           if DDEConv.SetLink('NETSCAPE' , 'WWW_OpenURL') then
                             if DDEConv.RequestData(URL +
                                                    ',,0x0,0x0') <> nil then
                               if DDEConv.SetLink('NETSCAPE', 'WWW_Activate') then
                                 URLFired := DDEConv.RequestData('0xFFFFFFFF,0x0') <> nil;
                           DDEConv.Free;
                         end else
                         if Pos('IEXPLORE.EXE',
                                UpApp) > 0 then begin
                           DDEConv:=TDDEClientConv.Create(nil);
                           DDEConv.ServiceApplication := App;
                           if DDEConv.SetLink('iexplore', 'WWW_OpenURL') then
                             if DDEConv.RequestData(URL + ',,0') <> nil then
                               if DDEConv.SetLink('iexplore', 'WWW_Activate') then
                                 URLFired := DDEConv.RequestData('0,0') <> nil;
                           DDEConv.Free;
                         end;
                         if UrlFired = false then
                           WinExec(StrPCopy(@p, URL), SW_SHOWNORMAL);
                       end;

                       procedure TForm1.Button1Click(Sender: TObject);
                       begin
                         StartNewBrowserWindow('http://www.borland.com');
                         StartNewBrowserWindow('http://www.yahoo.com');
                       end;

I've used it and it works... I now just saw this other FAQ:
Launching a web browser

                       Question:

                       How can I launch the computer's current web brower with a specific web site URL?

                       Answer:

                       Call the Win32 API function called HlinkNavigateString which is
                       declared in the UrlMon unit.

                       Example call:

                         HlinkNavigateString(Nil,'http://www.borland.com');

                       If you're calling this from an ActiveForm then call it like this:

                         HlinkNavigateString(ComObject,'http://www.borland.com');

Seems a lot simpler, but I don't know exactly what it does. Also, the first example gives you a lot more information...
Good luck!!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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