Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the windows dialing rules in .NET

This should be simple, but isn't apparently. Since..Windows 3 or so, there is a control panel called Phone or Phone & Modem. In that control panel is a bunch of information about how a modem would dial up, assuming you have a modem hooked up. For example, do you need to dial 9 to get out, what is the area code, and so forth. How can i access this information programmatically? I am using C# .NET 2010.

like image 470
Rob Avatar asked Dec 08 '11 22:12

Rob


2 Answers

You are going to need to use Tapi in Windows or pull the information from the registry. According to Microsoft Tapi 3.0 was not designed to be used from managed code, though the first link seems to have done it.

Some articles to look at:

  1. Tapi3.0 Application Development
  2. VB.Net accessing TAPI Dialing Rules

From Link #2

Take a look at these TAPI functions:

  1. lineGetTranslateCaps
  2. lineTranslateAddress
  3. lineTranslateDialog
  4. lineSetCurrentLocation
  5. lineGetCountry
  6. tapiGetLocationInfo

The info is stored in the Registry at: HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Telephony\Locations

like image 52
Mark Hall Avatar answered Oct 18 '22 02:10

Mark Hall


I couldn't find a way to access it through a .Net TAPI wrapper (after a not so long search) so I fired up procmon an found where it was stored in the registry, and here's the code that accesses it (you can adapt it to your specific needs):

RegistryKey locationsKey =
    Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Telephony\Locations");
if (locationsKey == null) return;
string[] locations = locationsKey.GetSubKeyNames();
foreach (var location in locations)
{
    RegistryKey key = locationsKey.OpenSubKey(location);
    if (key == null) continue;
    Console.WriteLine("AreaCode {0}",key.GetValue("AreaCode"));
    Console.WriteLine("Country {0}",(int) key.GetValue("Country"));
    Console.WriteLine("OutsideAccess {0}", key.GetValue("OutsideAccess"));
}

Note :

  1. I recommend to use an official API if there is a .net compatible one.
  2. This code is not guaranteed to work on other OSes than Win 7
  3. If you need to prompt the user to fill in these details you can start the configuration tool using :

Process.Start(@"C:\Windows\System32\rundll32.exe",@"C:\Windows\System32\shell32.dll,Control_RunDLL C:\Windows\System32\telephon.cpl");

like image 30
Nasreddine Avatar answered Oct 18 '22 01:10

Nasreddine