Solved

Modems in the Registry

Posted on 2003-12-02
9
381 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 1

Accepted Solution

by:
Binsky earned 250 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

773 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