DelphiFAQ Home Search:

List all User Identities in a ComboBox

 

commentsThis article has not been rated yet. After reading, feel free to leave comments and rate it.

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!
Content-type: text/html

Comments:

 

 

NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.
 

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: