Habe mich etwas durch die Registry gewühlt und bekomme so eine Zuordnung aller installierten
Com-Devices zu Ihren FriendlyNames in einer Liste. Sieht etwas hässlich aus, geht aber ganz schnell und zeigt alles, was ich bauche.
Delphi-Quellcode:
unit uComNames;
interface
uses Registry, classes, Windows, Dialogs, Sysutils;
function GetComNames: TStrings;
implementation
function GetComNames: TStrings;
var
KeyNames1,KeyNames2,KeyNames3: TStrings;
Res: TStringList;
i,ii,iii: integer;
s,Key0:
string;
begin
KeyNames1 := TStringList.Create;
KeyNames2 := TStringList.Create;
KeyNames3 := TStringList.Create;
Key0 := '
\SYSTEM\CurrentControlSet\Enum\';
Res := TStringList.Create;
with TRegistry.Create
do begin
try
RootKey := HKEY_LOCAL_MACHINE;
if OpenKeyReadOnly(Key0)
then begin
GetKeyNames(KeyNames1);
for i:=0
to KeyNames1.Count-1
do begin
OpenKeyReadOnly(Key0+KeyNames1[i]+'
\');
GetKeyNames(KeyNames2);
for ii:=0
to KeyNames2.Count-1
do begin
OpenKeyReadOnly(Key0+KeyNames1[i]+'
\'+KeyNames2[ii]+'
\');
GetKeyNames(KeyNames3);
for iii:=0
to KeyNames3.Count-1
do begin
OpenKeyReadOnly(Key0+KeyNames1[i]+'
\'+KeyNames2[ii]+'
\'+KeyNames3[iii]+'
\');
if KeyExists('
Device Parameters')
then begin
s := ReadString('
FriendlyName');
OpenKeyReadOnly(Key0+KeyNames1[i]+'
\'+KeyNames2[ii]+'
\'+KeyNames3[iii]+'
\Device Parameters\');
if ValueExists('
PortName')
then begin
s := ReadString('
PortName')+'
|'+s;
if Pos('
COM',s)=1
then Res.Add(s+'
|'+KeyNames1[i]);
end;
end;
end;
end;
end;
end;
finally
CloseKey;
Free;
end;
end;
//sortieren
Res.Sort;
Result := Res;
end;
end.