2016-02-18 51 views
4

有沒有任何機會從Windows控制中心通過使用C#程序打開調制解調器對話框?從窗口打開調制解調器配置對話框(C#)

具體的對話是: 窗口 - >控制中心 - >電話和調制解調器 - >選項卡高級 - >選擇供應商 - >按鈕配置

相應地開始是顯示在任務管理器的DLLHOST過程。可執行程序。

感謝和親切的問候 藤

回答

0

您可以通過「跑」的TELEPHON.CPL「程序」,打開電話和調制解調器控制面板項目。您可以通過直接使用p/invoke使用SHELL32函數或使用RunDll32來完成此操作。

RunDll32是一個包含在Windows中的程序,它加載一個DLL,並在其中運行一個函數,如命令行參數指定的那樣。這通常是shell(瀏覽器)運行控制面板小程序的方式。

您也可以直接使用shell32函數直接加載CPL。

這裏的示例代碼:

[System.Runtime.InteropServices.DllImport("shell32", EntryPoint = "Control_RunDLLW", CharSet = System.Runtime.InteropServices.CharSet.Unicode, SetLastError = true, ExactSpelling = true)] 
private static extern bool Control_RunDLL(IntPtr hwnd, IntPtr hinst, [System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)] string lpszCmdLine, int nCmdShow); 

private void showOnMainThread_Click(object sender, EventArgs e) 
{ 
    const int SW_SHOW = 1; 
    // this does not work very well, the parent form locks up while the control panel window is open 
    Control_RunDLL(this.Handle, IntPtr.Zero, @"telephon.cpl", SW_SHOW); 
} 

private void showOnWorkerThread_Click(object sender, EventArgs e) 
{ 
    Action hasCompleted = delegate 
    { 
     MessageBox.Show(this, "Phone and Modem panel has been closed", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Information); 
    }; 

    Action runAsync = delegate 
    { 
     const int SW_SHOW = 1; 
     Control_RunDLL(IntPtr.Zero, IntPtr.Zero, @"telephon.cpl", SW_SHOW); 
     this.BeginInvoke(hasCompleted); 
    }; 

    // the parent form continues to be normally operational while the control panel window is open 
    runAsync.BeginInvoke(null, null); 
} 

private void runOutOfProcess_Click(object sender, EventArgs e) 
{ 
    // the control panel window is hosted in its own process (rundll32) 
    System.Diagnostics.Process.Start(@"rundll32.exe", @"shell32,Control_RunDLL telephon.cpl"); 
}