0

I have a wpf application,Now I want to run the button_click functionality from the Command prompt.

EDIT: The button click collect the list of drivers and show it. Now I want to call this method from command prompt.

4

2 回答 2

1

您可以随时使用 Environment.GetCommandLineArgs() 检索从命令行传递的参数。

if( Environment.GetCommandLineArgs().Any( cmd => cmd == "--click-button" ) )
{
    do_button_click_method();
}
于 2013-05-24T09:28:36.467 回答
-1

导入 DLL

[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
private static extern System.IntPtr GetCommandLine();

在你的 Form_OnLoad

IntPtr ptr = GetCommandLine();

var commandline = Marshal.PtrToStringAuto(ptr);
if (!string.IsNullOrEmpty(commandline) && commandline == "yourCommand")
{
    button_click(this, new EventArgs());
}

现在,您可以从命令行运行 button_click 函数

于 2013-05-24T09:26:27.443 回答