2013-05-24 3 views
0

wpf 응용 프로그램이 있습니다. 이제 명령 프롬프트에서 button_click 기능을 실행하려고합니다.명령 프롬프트에서 실행 단추 누르기 기능

편집 : 버튼을 클릭하여 드라이버 목록을 수집하고 표시하십시오. 이제 명령 프롬프트에서이 메서드를 호출하고 싶습니다.

+0

왜이 방법을 사용 하시겠습니까 ?? functionallity 테스트를 위해 맞습니까? 그렇다면 테스트 케이스를 만드는 것이 어떻습니까? – shadow

+0

편집 부분보기 .. – vikky

답변

-1

수입 DLL

IntPtr ptr = GetCommandLine(); 

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

이제 Form_OnLoad에

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

, 당신은 당신이에서 전달 된 매개 변수를 검색 할 Environment.GetCommandLineArgs()를 사용할 수

1

명령 행에서 기능을 button_click 실행할 수 있습니다 명령 행.

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