Open modem configuration dialog from windows (C#)

171 views Asked by At

is there any opportunity to open the modem dialog from the windows control center by using a c# program?

The concrete dialog is: Windows -> Control center -> Telephone and modem -> tab advanced -> select provider -> button configuration

The process which is started is show in the task manager as dllhost.exe.

Thanks and kind regards Bine

1

There are 1 answers

0
William On

You can open the Phone and Modem control panel item by "running" the telephon.cpl "program". You can do this by using the SHELL32 function directly by p/invoke, or by using RunDll32.

RunDll32 is a program included with windows, which loads a DLL, and runs a function within it, as specified by the command line arguments. This is typically how the shell (explorer) runs control panel applets.

You can also load the CPL directly by using the shell32 function yourself.

Here's example code:

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