Autor Beitrag
matzehl
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 44



BeitragVerfasst: Di 08.02.05 10:15 
Morgäääähn !!!

Kurz und Knapp: Ich will ein kleines Setup für mein Programm schreiben. Wie kann ich die Seriellen Schnittstellen meines Rechners zählen (inklusive USB)?

MfG

Matze :wink2:
chrisw
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 439
Erhaltene Danke: 3

W2K
D7
BeitragVerfasst: Di 08.02.05 10:25 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
procedure EnumComPorts(Ports: TStrings);
var
  I  : Integer;
  TmpPorts: TStringList;
begin
  Ports.Clear;
  with TRegistry.Create do
    try
      TmpPorts := TStringList.Create;
{$IFDEF DELPHI_5_OR_HIGHER}
      Access := KEY_READ;
{$ENDIF}
      RootKey := HKEY_LOCAL_MACHINE;
      if OpenKey('HARDWARE\DEVICEMAP\SERIALCOMM', False) then
      begin
        GetValueNames(TmpPorts);
        for I := 0 to TmpPorts.Count - 1 do
          TmpPorts[I] := ReadString(TmpPorts[I]);
        TmpPorts.Sort;
        Ports.Assign(TmpPorts);
        TmpPorts.Free;
      end;
    finally
      Free;
    end;
end;


Anzahl steht dann im count des TStrings

_________________
Man sollte keine Dummheit zweimal begehen, die Auswahl ist schließlich groß genug.
matzehl Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 44



BeitragVerfasst: Di 08.02.05 11:11 
Coole Sache. Funzt das auch unter Win98 und 2000?
SchelmVomElm
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 154

W2K Pro
D5 Pro
BeitragVerfasst: Di 08.02.05 11:47 
Source von Chrisw läuft unter NT, W2K und XP

Für 9x und ME must geht's so:

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
procedure ScanRegEnum(var Strings: TStrings; const Key: String);
  var
    LKey : TStringList;
    LName : TStringList;
    i : Integer;
    Driver, PortName : String;
    PortSubClass : Byte;
  begin
    if not Reg.OpenKeyReadOnly(Key) then Exit;
    LName := TStringList.Create;
    Reg.GetValueNames(LName);
    i := LName.IndexOf('class');
    if i >= 0 then
    begin
      if (Reg.GetDataType('class') = rdString) and
         (LowerCase(Reg.ReadString('class')) = 'ports') and
         (Reg.GetDataType('driver') = rdString) and
         (Reg.GetDataType('portname') = rdString) then
      begin
        Driver := Reg.ReadString('driver');
        PortName := Reg.ReadString('portname');
        if(Reg.OpenKeyReadOnly('\System\CurrentControlSet\Services\Class\'+ Driver)) and
          (Reg.ReadBinaryData('PortSubClass',PortSubClass,1) = 1) and
          (PortSubClass = 1) and (Strings.IndexOf(PortName) < 0) then
          Strings.Add(PortName);
      end;
    end;
    LName.Free;
    Reg.OpenKeyReadOnly(Key);
    if Reg.HasSubKeys then
    begin
      LKey := TStringList.Create;
      Reg.GetKeyNames(LKey);
      for i := 0 to LKey.Count - 1 do
      begin
        ScanRegEnum(Key + '\' + LKey[i]);
      end;
      LKey.Free;
    end;
  end;


Mit USB Ports gehen beide Codes nicht!

_________________
for(;P("\n"),R--;P("|"))for(e=C;e--;P("_"+(*u++/8)%2))P("|"+(*u/4)%2);