Search code examples
c#.netrulestapidialing

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.


Solution

  • 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");