DelphiFAQ Home Search:
General :: Programming :: Delphi :: Network
Network (local network and Internet) programming under Windows with Delphi.

Articles:

This list is sorted by recent document popularity (not total page views).
New documents will first appear at the bottom.

Featured Article

List all User Identities in a ComboBox

The handy procedure GetIdentities() retrieves all user identities on a Windows system and and returns them for display in a TComboBox.
This can be useful for email tools.

procedure GetIdentities(cbIdentities: TComboBox);
 var
   slIdentities: TStringList;
   sUser: string;
   sLastUsername: string;
   i: Integer;
 begin { GetIdentities }
   cbIdentities.Items.Clear;
   sLastUsername := '';
   slIdentities := TStringList.Create;
   with TRegistry.Create do
   begin
     RootKey := HKEY_CURRENT_USER;
     if OpenKey('Identities', False) then
     begin
       sLastUsername := ReadString('Last Username');
       GetKeyNames(slIdentities);
       CloseKey;
     end; { OpenKey() }
 
     // get all the user names
    for i := 0 to slIdentities.Count-1 do
     begin
       if OpenKey('Identities\'+slIdentities[i], False) then
       begin
         sUser := ReadString('Username');
         cbIdentities.Items.Add(sUser+' - '+slIdentities[i]);
         if sUser=sLastUsername then
           cbIdentities.ItemIndex := i;
         CloseKey;
       end; { OpenKey() }
     end; { for i }
     Free;
   end; { with TRegistry.Create }
   slIdentities.Free;
 end; { GetIdentities }
 
You don't like the formatting? Check out SourceCoder then!
Generated 0:01:31 on Apr 23, 2017