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.
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.
您可以随时使用 Environment.GetCommandLineArgs() 检索从命令行传递的参数。
if( Environment.GetCommandLineArgs().Any( cmd => cmd == "--click-button" ) )
{
do_button_click_method();
}
导入 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 函数