Capture all of the modems installed

A computer can have several modems installed and working. What I need is to capture each one of them and list them them in the a listbox. Like

U.S. Robotics 33.6K Voice INT PnP
NetoDragon 56K Voice Modem
etc...

Whoever answers this ok I promise I´ll increase the points.
si0347429Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

geobulCommented:
Hi,

I think you can find that list in the registry:

1.Get all subkeys from:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\Root\MODEM
2. For each subkey read its 'FriendlyName' value (or DeviceDesc if you want).
3. Add that string to your ListBox.

Regards, Geo
0
raidosCommented:
Add Registry unit to Uses clause;

I was just about to sit down and write this function when geobul gave you his comment on how to do it.
I went ahead and wrote it anyway...
Anyway this is what i came up with...

Function PopulateModems(Items: TStrings; DeviceDesc: Boolean): Boolean;
Const
  Path = 'SYSTEM\CurrentControlSet\Enum\Root\MODEM';
Var
  aReg: TRegistry;
  aKeyList: TStrings;
  Loop: Integer;
  TmpStr: string;
Begin
  Result := False;
  aReg := TRegistry.Create;
  aReg.RootKey := HKEY_LOCAL_MACHINE;
  if aReg.OpenKeyReadOnly(Path) then Begin
    aKeyList := TStringList.Create;
    aReg.GetKeyNames(aKeyList);
    Items.BeginUpdate;
    Items.Clear;
    for Loop := 0 To aKeyList.Count-1 do Begin
      aReg.CloseKey;
      if aReg.OpenKeyReadOnly(Path + '\' + aKeyList[Loop]) then Begin
        if DeviceDesc Then
          TmpStr := aReg.ReadString('DeviceDesc')
        Else
          TmpStr := aReg.ReadString('FriendlyName');
        Items.Add(TmpStr);
        Result := True;
      end else Begin
         Result := FALSE;
         Break;
      end;
    end;
    aKeyList.Free;
    aReg.CloseKey;
    Items.EndUpdate;
  end;
  aReg.Free;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  PopulateModems(ListBox1.Items, False);
end;


Regards
//raidos
0
si0347429Author Commented:
I made a test. But there´s one problem. When you install it gets everything ok. When you remove the modem and uninstall it, it´s description still appears in the registry, so what happens is that it says that the computer has a modem but i really doesn´t. That´s because it continues in the registry.
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

si0347429Author Commented:
Also the path you guys gave me is wrong. The right path is " \SYSTEM\ControlSet001\Control\Class\{4D36E96D-E325-11CE-BFC1-08002BE10318}\0000" for NT Plat forms and " '\System\CurrentControlSet\Services\Class\Modem\0000' " for Win9x.
0
geobulCommented:
ControlSet001 is totally wrong. It always should be CurrentControlSet branch. ControlSetXXX means one of the predefined local users and CurrentControlSet means the user that is currently logged on. If your account is the first local account then both will be equal but if you logon using another account then they will not.

Well, in my XP modems disapear from the key I've given after removing them and even MODEM key disapears if I remove the last modem. I have nothing to say more.

Regards, Geo
0
si0347429Author Commented:
Ok, thanx for the information about the key, but one thing. I made a test in Windows 2000 and it didn´t remove the keys from the registry. Is there a way to know which modem is the one that´s installed. Because it shows me three because in the registry there are three but actually is only 2
0
si0347429Author Commented:
Or maybe does anyone know how to access he modem and get it´s details just like in the window´s hardware manager.
0
si0347429Author Commented:
I guess this question is too hard or it´s not possible to do it.
0
geobulCommented:
I will say that again: check CurrentControlSet branch. I tested that on Win2000 and it was working as expected, i.e. removed the modem description from there after removing the corresponding modem via Control Panel. Perhaps you are not refreshing your regedit. Close it, open it again and you'll see that everything is OK.
0
si0347429Author Commented:
Oh ok. I see what you did. You Uninstalled it. But i only removed the modem from my PCI Slot. So it doesn´t remove from the registry but it doesn´t give me any error and it doesn´t appear in the control panel. I´ve been doing a search on how to do it in a different and right way. I found out that I can get all the modems through WIndows TAPI. Do you know something about it ???
0
geobulCommented:
You said the following:
>A computer can have several modems installed and working.What I need is to capture each one of them and list them them in the a listbox

>When you remove the modem and uninstall it, it´s description still appears in the registry,

>Is there a way to know which modem is the one that´s installed.

I'm sorry for misunderstanding your statements. I'm a software professional and the term 'installed' means something different to me.
0
si0347429Author Commented:
Did anyone here said that you´re not a software professional or am I blind. Ok, but what I was trying to say is only remove the modem from it´s slot without uninstalling it. It´s registry still stays there.
0
geobulCommented:
I mean: sorry for misunderstanding. You didn't say anything wrong, of course. It's my fault that I understood that another way. Now it's clear to me what you are after.

A solution could be to get the other descriptions from the registry including the port (com1, com2, etc) where a particular modem has been installed and to try to communicate with that port in a certain way. I have found some code that may help you :

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

var
  CommPort : string;

//initilize a modem

procedure InitModem;
var
  CommPortTimeOuts: TCommTimeouts;
  DCB: TDCB;
  hCommFile : THandle;
  ReadBuffer: array[0..100] of char;
  NumberRead: DWord;
begin

   { Open the comm port. }
   hCommFile := CreateFile(PChar(CommPort),GENERIC_READ +
GENERIC_WRITE,0,nil,OPEN_EXISTING,FILE_FLAG_WRITE_THROUGH,0);
   if hCommFile = INVALID_HANDLE_VALUE then begin
     ShowMessage('Unable to open COM1!');
     exit;
   end;

   try
     { Set Timeout values for the comm port. }
     CommPortTimeOuts.ReadIntervalTimeout        := 100;
     CommPortTimeOuts.ReadTotalTimeoutMultiplier  := 100;
     CommPortTimeOuts.ReadTotalTimeoutConstant    := 0;
     CommPortTimeOuts.WriteTotalTimeoutMultiplier := 0;
     CommPortTimeOuts.WriteTotalTimeoutConstant  := 0;
     SetCommTimeOuts(hCommFile,CommPortTimeOuts);

     { Set the comm port parameters. }
     GetCommState(hCommFile,DCB);
     DCB.BaudRate := 1200;
     DCB.ByteSize := 7;
     DCB.StopBits := ONESTOPBIT;
     DCB.Parity  := EVENPARITY;
     SetCommState(hCommFile,DCB);

     { Send initialization string to the port. }
     ReadBuffer := '';
     StrPCopy(ReadBuffer,'ATZ' + #13 + #10);

     WriteFile(hCommFile,ReadBuffer,Length(ReadBuffer),NumberRead,NIL);


     { Get a response from the port. }
     ReadBuffer := '';
     if not ReadFile(hCommFile,ReadBuffer,100,NumberRead,NIL) then ShowMessage('Cannot find the modem');
     if (string(ReadBuffer)) = '' then ShowMessage('Cannot find the modem')
     else ShowMessage('OK');
   except
     ShowMessage('Cannot find the modem');
   end;


   { Close the port. }
   CloseHandle(hCommFile);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  CommPort := 'COM1';
  InitModem;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  hCommFile : THandle;
  ModemStat : DWord;
begin
  CommPort := 'COM1';

 {Open the comm port}
  hCommFile := CreateFile(PChar(CommPort),
                          GENERIC_READ,
                          0,
                          nil,
                          OPEN_EXISTING,
                          FILE_ATTRIBUTE_NORMAL,
                          0);
  if hCommFile = INVALID_HANDLE_VALUE then
  begin
    ShowMessage('Unable to open '+ CommPort);
    exit;
  end;

 {Get the Modem Status}
  if GetCommModemStatus(hCommFile, ModemStat) <> false then begin
    if ModemStat and MS_CTS_ON <> 0 then
      ShowMessage('clear to send  on.');
    if ModemStat and MS_DSR_ON <> 0 then
      ShowMessage('data set ready on.');
    if ModemStat and MS_RING_ON <> 0then
      ShowMessage('ring indicator on.');
    if ModemStat and MS_RLSD_ON <> 0 then

    ShowMessage('receive line signal detect is on.');
  end;
  {Close the comm port}
  CloseHandle(hCommFile);
end;

end.

Regards, Geo
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
si0347429Author Commented:
Did you ever work with Telephony API ?
0
geobulCommented:
No
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.