I hope this will solve your problem.
 ozgur
 usage :
GetPortList(Combobox1.Items);
 unit:
 unit CommPortList;
interface

uses Windows, Classes;

function CheckOS(var VersionInfo : TOSVersionInfo) : Integer;
procedure GetPortList(Strings : TStrings);

implementation
{$BOOLEVAL OFF}
uses Registry,SysUtils;

function CheckOS(var VersionInfo : TOSVersionInfo) : Integer;
begin
{
dwOSVersionInfoSize: DWORD;
dwMajorVersion: DWORD;
dwMinorVersion: DWORD;
dwBuildNumber: DWORD;
dwPlatformId: DWORD;
szCSDVersion: array[0..127] of AnsiChar; // Maintenance string for PSS usage
}
VersionInfo.dwOSVersionInfoSize := SizeOf(VersionInfo);
if GetVersionEx(VersionInfo) then
CheckOS := VersionInfo.dwPlatformId
else
CheckOS := -1;
end;

 procedure GetPortList(Strings : TStrings);
var Reg : TRegistry;

procedure ScanRegHardware;
var
i : integer;
PortName : string;
LName : TStringList;
begin
if Reg.OpenKeyReadOnly('\hardware\devicemap\serialcomm') then
begin
LName := TStringList.Create;
Reg.GetValueNames(LName);
for i := 0 to LName.Count - 1 do
begin
if Reg.GetDataType(LName.Strings[i]) = rdString then
begin
PortName := Reg.ReadString(LName.Strings[i]);
if Strings.IndexOf(PortName) < 0 then
Strings.Add(PortName);
end
end;
LName.Free;
end
end;

procedure ScanRegEnum(Key : String);
// This Subprocedure recurses thru all keys below key
var
LKey : TStringList;
LName : TStringList;
i : Integer;
Driver, PortName : String;
PortSubClass : Byte;
begin
if not Reg.OpenKeyReadOnly(Key) then // Danke Andreas Schmidt!
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') or //normal Serialports like 
COMx
(LowerCase(Reg.ReadString('class')) = 'modem')) and //some abnormal onboard 
Modems
(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) or //Ports
(PortSubClass = 2)) and //Modems
(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;

var
VersionInfo : TOSVersionInfo;
begin
if CheckOS(VersionInfo) > 0 then
if VersionInfo.dwMajorVersion >= 4 then
begin
Reg := TRegistry.Create;
Reg.RootKey := HKEY_LOCAL_MACHINE;
if VersionInfo.dwMajorVersion > 4 then
ScanRegHardware //Win 2k, XP
else if VersionInfo.dwMinorVersion > 0 then
ScanRegEnum('\enum') //Win9x, mE
else
ScanRegHardware; //WinNT
Reg.Free;
end;
end;

end.


On 8/8/05, Katja Bergman <[EMAIL PROTECTED]> wrote: 
> 
> --- In [email protected], Vahan Yoghoudjian <[EMAIL PROTECTED]> wrote:
> > Hi Katja....
> >
> > Just one question
> >
> > Why using the registry for this is not reliable? can you give some
> > examples please
> >
> > Thanks
> > Vahan
> 
> There are several reasons why the Registry might be unreliable. First
> of all, the security mechanism might have blocked access for the
> current user to some parts of the Registry. WMI is a connection to a
> system service that runs with a system account and thus always has
> access to this information.
> Another reason is that in future versions, the names and locations of
> these registry settings might change. Unless you read on an OFFICIAL
> microsoft site that it's safe to read these values from the registry,
> you will have to assume they are not.
> And of course it is possible that the Registry doesn't even contain
> the information that you are looking for. In my case, for example, I
> see \Device\Serial0, \Device\Serial1 and Winachsf0. The last one
> happens to be a modemcard in my system.
> 
> The flaw in your code while reading the Registry is simple. By using
> GetValueNames you read just the names of all these keys. You don't
> need the names, but the values. So you must get this list of names and
> enumerate them, calling ReadString() for every value in this list.
> Then you get the values.
> 
> However, I just think the use of WMI offers a lot more power in this
> case, since you can get more information about these devices than just
> the Device ID's of these ports. And basically, WMI just uses some
> SQL-like queries to get the data you want. You need to experiment with
> it a bit, but once you realise it's powers, it can be a valuable tool
> to use.
> 
> WMI is available in all recent versions of Windows. WMI is installed
> with Windows Me, Windows 2000, Windows XP and Windows Server 2003. For
> Windows 98 and Windows NT 4.0, WMI is available as an Internet
> download from http://www.microsoft.com/downloads. Search for the
> download "Windows Management Instrumentation (WMI) CORE 1.5 (Windows
> 95/98/NT 4.0)."
> 
> Also take a look at
> http://www.microsoft.com/technet/scriptcenter/resources/wmifaq.mspx
> where I stole that quote above. :)
> 
> In my personal experience, WMI is just a great way to collect system
> information, simply because you query the system and the WMI service
> has the required access to the information that you want to know. And
> it's pretty fast too.
> 
> With kind regards,
> X Katja Bergman.
> 
> 
> 
> -- 
> Ozgur Cetin
> Comon Professionals
> Industrial&Software Engineer


[Non-text portions of this message have been removed]



------------------------ Yahoo! Groups Sponsor --------------------~--> 
<font face=arial size=-1><a 
href="http://us.ard.yahoo.com/SIG=12hjp0svm/M=362131.6882499.7825260.1510227/D=groups/S=1705115362:TM/Y=YAHOO/EXP=1123682022/A=2889191/R=0/SIG=10r90krvo/*http://www.thebeehive.org
">Get Bzzzy! (real tools to help you find a job) Welcome to the Sweet Life 
- brought to you by One Economy</a>.</font>
--------------------------------------------------------------------~-> 

-----------------------------------------------------
Home page: http://groups.yahoo.com/group/delphi-en/
To unsubscribe: [EMAIL PROTECTED] 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/delphi-en/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to