Solved

How to detect if internet and a browser is installed?

Posted on 1998-06-19
5
189 Views
Last Modified: 2010-04-04
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
Comment
Question by:omsec
5 Comments
 
LVL 10

Expert Comment

by:Jacco
ID: 1354100
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
 
LVL 2

Author Comment

by:omsec
ID: 1354101
do I have to include a special (Active-X) Control/Unit ?
0
 

Expert Comment

by:dskowron
ID: 1354102
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
 
LVL 2

Author Comment

by:omsec
ID: 1354103
ShellExecute('http:\\www.microsoft.com'); does not work
0
 
LVL 6

Accepted Solution

by:
Holger101497 earned 50 total points
ID: 1354104
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

820 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