2011-12-08 31 views
10

Điều này phải đơn giản, nhưng không rõ ràng. Kể từ..Windows 3 hoặc hơn, có một bảng điều khiển được gọi là Điện thoại hoặc Điện thoại & Modem. Trong bảng điều khiển đó là một loạt các thông tin về làm thế nào một modem sẽ quay số, giả sử bạn có một modem nối. Ví dụ, bạn có cần quay số 9 để thoát ra không, mã vùng là gì, v.v. Tôi có thể truy cập thông tin này bằng cách nào? Tôi đang sử dụng C# .NET 2010.Cách tìm quy tắc quay số cửa sổ trong .NET

Trả lời

8

tôi không thể tìm thấy một cách để truy cập thông qua một .Ne t TAPI wrapper (sau khi tìm kiếm không quá lâu) vì vậy tôi bắn lên procmon một tìm thấy nơi nó được lưu trữ trong registry, và đây là đoạn code mà truy cập vào nó (bạn có thể điều chỉnh nó theo nhu cầu cụ thể của bạn):

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

Lưu ý:

  1. tôi khuyên bạn nên sử dụng một API chính thức nếu có một tương thích .net.
  2. Mã này không được bảo đảm để làm việc trên hệ điều hành khác ngoài Win 7
  3. Nếu bạn cần phải nhắc nhở người dùng để điền vào những chi tiết bạn có thể bắt đầu công cụ cấu hình sử dụng:

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

12

Bạn sẽ cần sử dụng Tapi trong Windows hoặc lấy thông tin từ sổ đăng ký. Theo Microsoft Tapi 3.0 không được thiết kế để được sử dụng từ mã được quản lý, mặc dù liên kết đầu tiên dường như đã thực hiện nó.

Một số bài viết để xem xét:

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

Từ Liên kết # 2

Hãy nhìn vào các chức năng TAPI:

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

Thông báo thông tin được lưu trữ trong Registry tại địa chỉ: HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Telephony\Locations

+0

Điều này thật tuyệt vời, nhờ cả hai bạn. – Rob

0

Thêm mã để nhận tiền tố

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([email protected]"\"+location); 


     } 

    }