从 Windows (C#) 打开调制解调器配置对话框

Posted

技术标签:

【中文标题】从 Windows (C#) 打开调制解调器配置对话框【英文标题】:Open modem configuration dialog from windows (C#) 【发布时间】:2016-05-30 21:42:13 【问题描述】:

是否有机会使用 c# 程序从 Windows 控制中心打开调制解调器对话框?

具体的对话框是: Windows -> 控制中心 -> 电话和调制解调器 -> 高级选项卡 -> 选择提供商 -> 按钮配置

启动的进程在任务管理器中显示为 dllhost.exe。

感谢和亲切的问候 宾恩

【问题讨论】:

【参考方案1】:

您可以通过“运行”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");

【讨论】:

以上是关于从 Windows (C#) 打开调制解调器配置对话框的主要内容,如果未能解决你的问题,请参考以下文章

如何使用从SIM卡检索的信息配置调制解调器模块

宽带连接错误,显示(调制解调器或其他连接设备报告了一个错误)怎么解决啊?

windows11最低配置要求

如何配置Mac OS X 与 Windows之间共享网络

在第一次使用 ISDN 调制解调器 (C#) 后拨打电话号码时挂断

如何在 Windows 中获取 COM 端口的友好名称?