I need a way to use the WMI to find the name of a modem (or other device) which is currently attatched to a COM port which I already know.
For example lets say I have already extracted that the device I want is on COM port 3 and I also know it is a modem, how can I find the name of the modem associated with that COM port.
Currently I have code using Win32_PnPEntity which can extract a list of pnp devices with either modem or COM in the name but unfortunatley when I return the COM devices they do not carry the modem name and when I extract modem device they do not associate with a COM port (so if I have two modems attached I do not know which is in COM port 3). I have also found a Win32_SerialPort function but this does not return all devices attatched to my computer via serial ports.
const wbemFlagForwardOnly = $00000020;
var
FSWbemLocator : OLEVariant;
FWMIService : OLEVariant;
FWbemObjectSet: OLEVariant;
FWbemObject : OLEVariant;
oEnum : IEnumvariant;
iValue : LongWord;
ts : String;
begin;
FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
FWMIService := FSWbemLocator.ConnectServer('localhost', 'root\cimv2', '', '');
//This WMI service checks for plug and play devices
FWbemObjectSet:= FWMIService.ExecQuery('SELECT * FROM Win32_PnPEntity','WQL',wbemFlagForwardOnly);
//This WMI service which I didn't use checks for serial ports and what is on them - currently not displaying sufficient information}
//FWbemObjectSet:= FWMIService.ExecQuery('SELECT * FROM Win32_SerialPort','WQL',wbemFlagForwardOnly);
oEnum := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant;
while oEnum.Next(1, FWbemObject, iValue) = 0 do
begin
if not VarIsNull(FWbemObject.name) then
begin
ts:= String(FWbemObject.name);
if pos('(COM',ts)<>0 then
pnpForm.listbox1.items.add(ts);
end;
FWbemObject:=Unassigned;
end;
end;
AttachedTo
property. – RRUZ