5

ac# プログラムを使用して Windows コントロール センターからモデム ダイアログを開く機会はありますか?

具体的なダイアログは次のとおりです。Windows -> コントロール センター -> 電話とモデム -> 高度なタブ -> プロバイダの選択 -> ボタンの設定

開始されたプロセスは、タスク マネージャーに dllhost.exe として表示されます。

ありがとう、親切にバイン

4

1 に答える 1

0

telephon.cpl "プログラム"を "実行" することで、[電話とモデム] コントロール パネル項目を開くことができます。これを行うには、p/invoke で直接 SHELL32 関数を使用するか、RunDll32 を使用します。

RunDll32 は Windows に含まれるプログラムで、DLL をロードし、コマンド ライン引数で指定されたとおりにその中で関数を実行します。これは通常、シェル (エクスプローラー) がコントロール パネル アプレットを実行する方法です。

自分で 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");
}
于 2016-02-20T00:52:05.460 に答える