Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Capture all of the modems installed

Posted on 2003-11-25
15
Medium Priority
?
416 Views
Last Modified: 2010-04-05
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.
0
Comment
Question by:si0347429
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 6
15 Comments
 
LVL 17

Expert Comment

by:geobul
ID: 9823375
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
 
LVL 3

Expert Comment

by:raidos
ID: 9824161
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
 

Author Comment

by:si0347429
ID: 9849255
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:si0347429
ID: 9849310
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
 
LVL 17

Expert Comment

by:geobul
ID: 9849547
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
 

Author Comment

by:si0347429
ID: 9849900
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
 

Author Comment

by:si0347429
ID: 9860900
Or maybe does anyone know how to access he modem and get it´s details just like in the window´s hardware manager.
0
 

Author Comment

by:si0347429
ID: 9873369
I guess this question is too hard or it´s not possible to do it.
0
 
LVL 17

Expert Comment

by:geobul
ID: 9875547
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
 

Author Comment

by:si0347429
ID: 9877016
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
 
LVL 17

Expert Comment

by:geobul
ID: 9878136
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
 

Author Comment

by:si0347429
ID: 9881391
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
 
LVL 17

Accepted Solution

by:
geobul earned 750 total points
ID: 9881864
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
 

Author Comment

by:si0347429
ID: 9884015
Did you ever work with Telephony API ?
0
 
LVL 17

Expert Comment

by:geobul
ID: 9887398
No
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

598 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question