Modems in the Registry

I asked a question before in how to get the modems installed on the computer. They answered me on the registry. BUT, if I installed 3 modems on my computer it shows me 3. That´s right, but when I take one off, it still stays on the registry. Then it will also give me 3 modems installed and not 2. This test I made it in Windows 2000. How do I solve this problem ? Is there a subkey in the modem´s key that tell me which one is actually installed ( being used) ? Or something ...
si0347429Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

BinskyCommented:
I remember that question, or one like it...

The answer to that question was, that it isn't possible by just looking at the registry. (But I'm not sure myself though, I haven't tried it personally)

The solution provided was adding a flag yourself, which should tell you if a modem's connected, or at least reachable. So you could add a subkey yourself, connected to a modem_copnnection testing procedure or something like that.

Hope this helped,

Binsky
si0347429Author Commented:
How do I test if it´s connected ???
BinskyCommented:
Hi,

That's a good question! I must admit I hadn't looked into that yet... But, as I am currently working on a program that needs modem connectivity, I've ran a quick search on this...

What I've found so far is that it is possible to try to connect through the comm port the modem is connected to...In any basic serial port unit there will be a commportpresent procedure, try that for basic connection, if that works, try sending something to the modem, and test for correct reply (?)

I'll have time for more research tomorrow, or maybe later today...I'll probably be able to give you a clearer answer then, if you need it...

I read somewhere that if "AT" is entered in Hyperterm, the unit should respond with  "OK".

It should be possible to do the hyperterm stuff via the serial port.

Binsky
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

BinskyCommented:
I couldn't help myself, and searched some more...On a Borland page I've found the code for modem connection testing :

Note that this doesn't tell you which modem it is connecting to, you'd still need to figure that part out...It does tell you how to read the modem's status, and I guess that would do the trick!

Question:
How can I get the modem status under Win32?

Answer:
The following example demonstrates retrieving the current state
of the modem control-register values under Win32.

Example:
procedure TForm1.Button1Click(Sender: TObject);
var
  CommPort : string;
  hCommFile : THandle;
  ModemStat : DWord;
begin
  CommPort := 'COM2';

 {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('The CTS (clear-to-send) is on.');
    if ModemStat and MS_DSR_ON <> 0 then
      ShowMessage('The DSR (data-set-ready) is on.');
    if ModemStat and MS_RING_ON <> 0then
      ShowMessage('The ring indicator is on.');
    if ModemStat and MS_RLSD_ON <> 0 then
      ShowMessage('The RLSD (receive-line-signal-detect) is
on.');
end;

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

I found this at : http://www.lars.pl/ftp/Delphi/borland/faq/1444.HTM

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:
Hey Binsky,

   The source above worked great. Thanx alot. I know that in the registry it has it´s port number, so i can get i from there. Do you know if there´s a way to know from the registry which modem is active ? Or something...
BinskyCommented:
Hi again,

Well, I don't really know about that, but as I've said in my first post, I did find another thread on this, and the expert that solved it said that there wasn't a key that said which modem is active...

But with the code, you could "manually" check the modems in the registry, to see if they're alive, and create your own registry entry to store which modems are alive and which need ignoring.

On my own pc the only reference to my PCI modem was in  
HKEY_LOCAL_MACHINE/Enum/PCI/...../

(But I think you already know where to find the registry item)

As far as I know there isn't a key that says which is active. (That last one is the short answer ;-) )

Binsky
si0347429Author Commented:
I made a test that when I put a modem it adds another in the HKEY_LOCAL_MACHINE/Enum/PCI/...../. Then I take it off but it stays there. The only change that made was that the windows took a subkey off named "Control" from the modem that´s not being used. If i could test if this subkey exists. Do you know how ? Thanx for helping me
BinskyCommented:
If you know the exact string to search for, you could store that string yourself, and then do a strcomp(S1, S2);

This is a stringcompare function, that'll tell you if the string in the registry is the same as your stored string...(very case sensitive)

For another project I've created a search-the-registry-for-a-specific-string procedure, please note that this will need some tweaking for your specific needs, as I had the advantage that the registry keys I was searching for were numbered, you'd need to "ReadString("Control");" and compare the result from the readstring. (or something like that)


function .DoesSerialExistInReg(Serial : string) : boolean;
var
   MyReg           : TRegistry;
   index           : integer;
   TempIndex       : string;
   RegSerialString : string;
   Max : integer;
begin
   Result := false;
   Myreg := TRegistry.Create;
   with MyReg do
   begin
      Rootkey := HKEY_CURRENT_USER;//HKEY_LOCAL_MACHINE;
      if OpenKey('Insert specific Key here\' , True) then
      begin
        for index := 0 to Max do
        begin
          try
             RegSerialString   := ReadString('Control');                        except
             MessageDlg('There was an error while reading registry values', mtError, [mbOk], 0);
             result := false;
          end; // try..except
          if (Serial = RegSerialString) then
            Result := true;
        end; // for
      CloseKey;
      end; // openkey
   end; // with myreg do
   MyReg.Free;
end;

Binsky
BinskyCommented:
Did the solution help you?
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.