Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Modems in the Registry

Posted on 2003-12-02
9
Medium Priority
?
390 Views
Last Modified: 2010-04-06
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 ...
0
Comment
Question by:si0347429
  • 6
  • 3
9 Comments
 
LVL 1

Expert Comment

by:Binsky
ID: 9857680
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
0
 

Author Comment

by:si0347429
ID: 9860499
How do I test if it´s connected ???
0
 
LVL 1

Expert Comment

by:Binsky
ID: 9866011
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
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Accepted Solution

by:
Binsky earned 1000 total points
ID: 9866050
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

0
 

Author Comment

by:si0347429
ID: 9867614
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...
0
 
LVL 1

Expert Comment

by:Binsky
ID: 9867806
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
0
 

Author Comment

by:si0347429
ID: 9873387
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
0
 
LVL 1

Expert Comment

by:Binsky
ID: 9873490
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
0
 
LVL 1

Expert Comment

by:Binsky
ID: 9963146
Did the solution help you?
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

772 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