function GetPortNames(Names: TStrings): Boolean;
const
CS_REG_ACPI = '\SYSTEM\CurrentControlSet\Enum\ACPI';
CS_REG_FriendlyName = 'FriendlyName';
CS_REG_DeviceDesc = 'DeviceDesc';
CS_REG_ClassGUID = 'ClassGUID';
CS_REG_PORT_GUID = '{4D36E978-E325-11CE-BFC1-08002BE10318}';
var
Buf1, Buf2: TStrings;
i, j : Integer;
begin
Result := False;
Buf1 := TStringList.Create;
Buf2 := TStringList.Create;
with TRegistry.Create do
try
RootKey := HKEY_LOCAL_MACHINE;
if OpenKeyReadOnly(CS_REG_ACPI) then
begin
GetKeyNames(Buf1);
for i := 0 to Buf1.Count - 1 do
begin
Buf2.Clear;
if OpenKeyReadOnly(CS_REG_ACPI + PathDelim + Buf1[i]) then
begin
Buf2.Clear;
GetKeyNames(Buf2);
for j := 0 to Buf2.Count - 1 do
if OpenKeyReadOnly(CS_REG_ACPI + PathDelim + Buf1[i] + PathDelim + Buf2[0])
and ValueExists(CS_REG_ClassGUID)
and SameText(ReadString(CS_REG_ClassGUID), CS_REG_PORT_GUID) then
begin
if ValueExists(CS_REG_FriendlyName) then
Names.Add(ReadString(CS_REG_FriendlyName))
else if ValueExists(CS_REG_DeviceDesc) then
Names.Add(ReadString(CS_REG_DeviceDesc));
Break;
end;
end;
end;
Result := True;
end;
finally
Buf1.Free;
Buf2.Free;
Free;
end;
end;