Delphi .NET (2) Database (71) Delphi IDE (89) Network (39) Printing (3) Strings (12) VCL (83) Windows with Delphi (280)
Exchange Links About this site Links to us 
|
List all User Identities in a ComboBox
This 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
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;
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;
end;
Free;
end;
slIdentities.Free;
end;
| |  | |  | You don't like the formatting? Check out SourceCoder then!
Comments:
|