从命令提示符运行按钮单击功能

时间:2013-05-24 09:13:03

标签: c# wpf cmd buttonclick

我有一个wpf应用程序,现在我想从命令提示符下运行button_click功能。

修改 单击按钮可收集驱动程序列表并显示它。现在我想从命令提示符调用此方法。

2 个答案:

答案 0 :(得分:1)

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

if( Environment.GetCommandLineArgs().Any( cmd => cmd == "--click-button" ) )
{
    do_button_click_method();
}

答案 1 :(得分:-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功能
相关问题