uses Registry;
procedure TForm1.Button3Click(Sender: TObject);
var
reg : TRegistry;
ts : TStrings;
i : integer;
begin
reg := TRegistry.Create;
try
reg.RootKey := HKEY_LOCAL_MACHINE;
reg.OpenKey('hardware/devicemap/serialcomm',false);
ts := TStringList.Create;
try
reg.GetValueNames(ts); //获得子键下的所有项
for i := 0 to ts.Count -1 do
begin //把每一项下的串值显示在Memo1中
Memo1.Lines.Add(reg.ReadString(ts.Strings));
end;
finally
ts.Free;
end;
finally
reg.CloseKey;
reg.free;
end;
end;
以上程序可以判断哪些串口已经被使用.