C# 如何在.NET中查找windows拨号规则

C# 如何在.NET中查找windows拨号规则,c#,.net,rules,tapi,dialing,C#,.net,Rules,Tapi,Dialing,这应该很简单,但显然不是。从..Windows 3左右开始,有一个名为Phone或Phone&Modem的控制面板。在控制面板中有一组关于调制解调器如何拨号的信息,假设你已经连接了一个调制解调器。例如,您是否需要拨打9才能下车,区号是多少,等等。如何以编程方式访问此信息?我正在使用C#.NET 2010。您需要在Windows中使用Tapi或从注册表中提取信息。根据微软的说法,Tapi 3.0并非设计用于托管代码,尽管第一个链接似乎已经做到了这一点 要查看的一些文章: 来自链接#2 看看这些

这应该很简单,但显然不是。从..Windows 3左右开始,有一个名为Phone或Phone&Modem的控制面板。在控制面板中有一组关于调制解调器如何拨号的信息,假设你已经连接了一个调制解调器。例如,您是否需要拨打9才能下车,区号是多少,等等。如何以编程方式访问此信息?我正在使用C#.NET 2010。

您需要在Windows中使用Tapi或从注册表中提取信息。根据微软的说法,Tapi 3.0并非设计用于托管代码,尽管第一个链接似乎已经做到了这一点

要查看的一些文章:

  • 来自链接#2

    看看这些TAPI功能:

  • lineGetTranslateCaps
  • lineTranslatedAddress
  • lineTranslateDialog
  • lineSetCurrentLocation
  • lineGetCountry

  • 该信息存储在注册表中的以下位置:
    HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Telephony\Locations

    我找不到通过.Net TAPI包装器访问该信息的方法(经过不长的搜索),因此我在注册表中存储该信息的位置启动了一个find,下面是访问该信息的代码(您可以根据自己的具体需要进行调整):

    注意:

  • 如果有与.net兼容的API,我建议使用官方API
  • 此代码不能保证在Win7以外的其他操作系统上工作
  • 如果需要提示用户填写这些详细信息,可以使用以下命令启动配置工具:

  • Process.Start(@“C:\Windows\System32\rundll32.exe”,“C:\Windows\System32\shell32.dll,Control\RunDLL C:\Windows\System32\telephon.cpl”);

    多输入一些代码以获取前缀

    class Program
    {
        static void Main(string[] args)
        {
            string rootLocation = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Telephony\Locations";
            getRegistryValues(rootLocation);
            Console.ReadLine();
        }
    
        public static void getRegistryValues(string rootLocation)
        {
            RegistryKey locationsKey =
            Registry.LocalMachine.OpenSubKey(rootLocation);
            if (locationsKey == null) return;
            string[] locations = locationsKey.GetSubKeyNames();
            Console.WriteLine(locations.Length.ToString());
            foreach (var location in locations)
            {
                Console.WriteLine(location.ToString());
                RegistryKey key = locationsKey.OpenSubKey(location);
                if (key == null) continue;
                foreach (string keyName in key.GetValueNames())
                {                  
    
                    if (keyName.Equals("Prefixes"))
                    {
                        string[] Prefixes = ((string[])(key.GetValue(keyName)));
                        Console.Write("Prefixes ");
                        foreach (string prefix in Prefixes)
                        {
                            Console.Write(prefix);
                        }
    
                    }
                    else
                    {
                        Console.WriteLine(keyName + " {0}", key.GetValue(keyName));
                    }
    
                }
    
                getRegistryValues(rootLocation+@"\"+location);
    
    
            }
    
        }
    
    class Program
    {
        static void Main(string[] args)
        {
            string rootLocation = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Telephony\Locations";
            getRegistryValues(rootLocation);
            Console.ReadLine();
        }
    
        public static void getRegistryValues(string rootLocation)
        {
            RegistryKey locationsKey =
            Registry.LocalMachine.OpenSubKey(rootLocation);
            if (locationsKey == null) return;
            string[] locations = locationsKey.GetSubKeyNames();
            Console.WriteLine(locations.Length.ToString());
            foreach (var location in locations)
            {
                Console.WriteLine(location.ToString());
                RegistryKey key = locationsKey.OpenSubKey(location);
                if (key == null) continue;
                foreach (string keyName in key.GetValueNames())
                {                  
    
                    if (keyName.Equals("Prefixes"))
                    {
                        string[] Prefixes = ((string[])(key.GetValue(keyName)));
                        Console.Write("Prefixes ");
                        foreach (string prefix in Prefixes)
                        {
                            Console.Write(prefix);
                        }
    
                    }
                    else
                    {
                        Console.WriteLine(keyName + " {0}", key.GetValue(keyName));
                    }
    
                }
    
                getRegistryValues(rootLocation+@"\"+location);
    
    
            }
    
        }