×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Delphi - add trusted site in IE
2

Delphi - add trusted site in IE

Delphi - add trusted site in IE

(OP)
Hi there,

I work for a business who has a large client base spread across the UK. We have to add a specific URL to IE on each of our clients dedicated machines, and they really dont have the staff skills to do it themselves.

I've written a small program to perform all the updates we need done, bar one.

Is is possible to add a trusted site autopmatically from a delphi app. I've seen some VB code which is supposed to be able to do it, but its beyond my comprehension.

Thanks in advance for any responses.

RE: Delphi - add trusted site in IE

A quick look on Google (for trusted sites registry)found this information:
http://msdn.microsoft.com/workshop/security/szone/overview/esc_development.asp

and this (slightly more chatty):
http://www.microsoft.com/technet/scriptcenter/resources/qanda/feb05/hey0214.mspx

There is also some basic info on writing to the registry at:
http://delphi.about.com/od/windowsshellapi/l/aa081703a.htm

The registry key to change is
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains

Given the key, you can add your trusted sites to the registy (read the Delphi help on TRegistry and TRegIniFile).
This is a bit of test code I've created for the task (from the Delphi help example):

CODE

procedure TForm1.B_SubmitClick(Sender: TObject);
const
  KeyName ='Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains';
var
  Reg: tRegistry; //TRegistry;
  SectionName : string;
  nIntraNet,
  nTrusted,
  nInternetSites,
  nRestricted : word;

begin
  nIntraNet := 1;
  nTrusted := 2;
  nInternetSites := 3;
  nRestricted := 4;

  Reg := TRegIniFile.Create;  //create the key
  SectionName := E_WebSite.Text;       // This is the web site, without the HTTP - eg microsoft.com
  try
    Reg.RootKey := HKEY_CURRENT_USER; // write to this for all users, HKEY_CURRENT_USER for just the current user
    if Reg.OpenKey(KeyName + '\' + SectionName,TRUE) then  // open the key - the TRUE forces creation if its not there
      begin
        Reg.WriteInteger('http', nTrusted); // write the value - http or ftp can be used here
      end;
    Reg.CloseKey;
  finally
    Reg.Free;
  end;
end;

I've tested, but it might need some tweaking and should be straight forward to apply. It will probably have to run from  a script on login for all users to ensure it applies to each of them.

Don't forget to add the Registry unit to your uses clause.

Good luck

Cheers,
Chris

RE: Delphi - add trusted site in IE

ChrisGShultz you're right. I've approached the same issue in your way (using registry).  I wrote a simple program to quickly add sites to trusted zones in IE6. Just wanted to be convinced that it worked really. It seemed interesting to me to do that. :). Some trial and error investigations showed to me that for each site added in trusted zones of IE6 assuming site addresses were entered in the format:

[protocol://][prefix.]domain/somepath/tosomewhere.html

protocol = [http|https|ftp]
domain   = [aWord.???|aWord.??.??]
prefix   = zero or more words separated by "."


the following happened:


0. The text after domain is ignored


1. A key with same name as domain entered is added under the  registry key which Chris pointed out:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains


2. If there is a prefix then a subkey with its name is created
   
   2.1 A value with same name as protocol entered and value 2 is created under the prefix key

3. If there was no prefix than
  
   3.1 A value with same name as protocol entered and value 2 is created under the domain key


This was my code. Again nothing essentially different from what ChrisGShultz posted.



CODE

...

procedure AddTrustedSite(Site:string);
procedure DecodeSiteName(Site:string;
                         var Protocol:string;
                         var Prefix:string;
                         var Domain:string);

implementation

uses Registry, StrUtils;

...

procedure TForm1.Button1Click(Sender: TObject);
begin
    try
      AddTrustedSite(Edit1.Text);
    except
      on e:Exception do
        ShowMessage('Try logging in as Administrator : '+e.Message);
    end;
end;

///////////////////////////////////////////////////////////////
// procedure : AddTrustedSite
// purpose   : Perform in IE6 the equivalent of user actions:
//            - Tools|Internet Options|Security|Trusted|
//              <Type and Add site>
//
// assumptions:
//      Assumes that the Site is passed in following format:
    [protocol://][{prefix.}...] domain.extension
//////////////////////////////////////////////////////////////
procedure AddTrustedSite(Site:string);
var
  reg:TRegistry;
  sDomain:string;
  sPrefix:string;
  sProtocol:string;
begin

   DecodeSiteName(Site,sProtocol,sPrefix,sDomain);

   reg:=TRegistry.Create;
   try
      reg.RootKey:=HKEY_CURRENT_USER;

      if reg.OpenKey(TRUSTED_ZONES_KEY,false) then
      begin
          //Make sure the domain is added as a key in the trusted zones
          reg.OpenKey(sDomain,true);

          //If there is a prefix create a subkey of it
          if sPrefix<>'' then
             reg.OpenKey(sPrefix,true);

          //Add a value into the current key
          if sProtocol='' then
             reg.WriteInteger('*',TRUSTED)
          else
             reg.WriteInteger(sProtocol,TRUSTED);
      end
      else
        raise Exception.Create('Failed to open Trusted Zones registry');

   finally
       reg.Free;
   end;
end;

//////////////////////////////////////////////////////////////////
// procedure: DecodeSiteName
// purpose  : Decode given Site string into three parts according
//            to site format specified in AddTrustedSite comments
//////////////////////////////////////////////////////////////////
procedure DecodeSiteName(Site:string;
                         var Protocol:string;
                         var Prefix:string; var Domain:string);
var
  nPos,nDomainWords:integer;
  slTmp:TStringList;
begin
    //Extract the protocol if there is any
    nPos:=Pos('://',Site);
    if nPos>0 then
    begin
      Protocol:=Copy(Site,1,nPos-1);
      Site:=Copy(Site,nPos+3,length(Site)-(nPos+2));
    end;

    //Ignore any text after the trailing "/"
    nPos:=Pos('/',Site);
    if nPos>0 then
      Site:=Copy(Site,1,nPos-1);

    slTmp:=TStringList.Create;

    with slTmp do
    try
      Delimiter:='.';
      DelimitedText:=Site;

      //Are there at least three words in Site Address ??
      if Count>2 then
      begin
          //If the last words in the site are less than 2 letters long
          //Then the domain is made out of last three words
          //otherwise it is made out of the last two words
          if (length(Strings[Count-1])<3) and (length(Strings[Count-2])<3) then
          begin
              Domain:=Strings[Count-3]+'.'+Strings[Count-2]+'.'+Strings[Count-1];
              nDomainWords:=3;
          end
          else
          begin
              Domain:=Strings[Count-2]+'.'+Strings[Count-1];
              nDomainWords:=2;
          end;

          //The prefix is the remaining part of the Site address (if any is left)
          if Count>nDomainWords then
            Prefix:=StringReplace(Site,'.'+Domain,'',[])
          else
            Prefix:='';
      end
      else
      begin
          Domain:=Site;
          Prefix:='';
      end;


    finally
      slTmp.Free;
    end;
end;
...


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close