문제

너무 긴 이야기가 짧아서 컴퓨터가 부팅 될 때 몇 가지 사항을 자동화하려고합니다. 나는 이것을 수행하기 위해 C # 콘솔 애플리케이션을 작성한 다음 부팅시 실행될 Windows에서 일정 작업에 추가 할 것으로 생각했습니다. 내 문제는 한 가지 프로그램과 함께 암호가 필요하며 명령 줄을 통해 열 수있는 옵션이 없습니다. 따라서 수동으로 입력해야합니다. 내 생각은 Keepass 데이터베이스에서 암호를 검색하고 SendKeys를 사용하여 암호를 입력하고 프로그램에 로그인하는 것이 었습니다. 내가 갖는 문제는로드하는 데 걸리는 시간입니다. GUI 인터페이스가로드되었을 때의 탐지 방법이 없습니다. 이것을 감지 할 수있는 방법이 있습니까? 저는 제가 일해야만하는 것이 프로그램을 운영하는 데 사용 된 이래로 "프로세스"클래스입니다. 또한 process.start ()를 사용하여 실행 파일을 실행하면 프로그램이 로그인하기위한 다른 프로세스를 만듭니다. 그러나 Windows API 호출을 사용하여 볼 수있는 창이 없습니다.

괜찮 았어, 나는 다시 캡 할 수있다 ...

문제 : C # 제 3 자 프로그램이로드되었을 때 (즉, 스플래시 화면이 사라졌고 GUI가 사용자 상호 작용을위한 준비가되어 있습니다. - 프로세스가 실행 중이거나 그렇지 않은 경우에만 의존 할 수 없음을 의미합니다. 또한 타사 프로그램에 대한 명령 줄 옵션이 없거나 암호로 암호로 실행할 것입니다.

목표 : 암호 입력을 자동화하기 위해 SendKeys를 사용하려면하지만 제 3 자 응용 프로그램이로드를 완료 할 때까지 기다려야합니다.

노트 : C # .NET 3.NET 3.5 콘솔 응용 프로그램을 사용합니다 내 자신의 양식에 대한로드를 탐지하지는 않지만 제 3자가 그렇지 않으면 이것이 쉽습니다 (즉, Form_Loaded 이벤트 ...)

더 이상 자세히 알고 싶다면 나의 질문을 바라 보셔서 감사합니다.

업데이트 :

문제 해결! 내가받은 두 대답은 내가 원하는 솔루션을 알려줍니다. 그래서 나중에 누군가 가이 일이면 여기에 내가 일하는 일이 있습니다.

이 프로그램은 로그인 해야하는 일부 클라이언트 소프트웨어에 대한 로그인을 자동화합니다. 내 문제는 소프트웨어가 다른 많은 프로그램이 제공하는 명령 줄 프라미터에 대한 옵션이나 설명서를 제공하지 않기 때문에 키 파일이나 무언가로 로그인 할 수 있음을 알려줍니다. 이 프로그램은 또한 복사 및 붙여 넣기를 비활성화하여 암호를 수동으로 입력해야합니다. 이와 같은 암호를 사용하면 암호를 사용하는 경우 큰 통증이며 패턴이없는 긴 복잡한 것들을 사용하십시오. 그래서 저는이 프로그램을 직장에서 내 이익을 위해이 프로그램을 썼습니다. Windows 시스템에 로그온에서 실행되도록 예약하고 클라이언트 소프트웨어를 열고 자동으로 로그인을 수행합니다.

//
// IMPORTANT Windows API imports....
//

[DllImport("user32.dll", SetLastError = true)]
private static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint procId);

[DllImport("user32.dll", SetLastError = true)]
private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow); 

[DllImport("user32.dll", SetLastError = true)]
private static extern bool SetForegroundWindow(IntPtr hWnd);


// When I get to this point in my code, I already had the password and window title...
string password = "password";
string title = "window title";

// This gets a handle to the window I want where "title" is the text in the title
// bar of the window as a string.
// This is a Windows API function that must be imported by DLLImport
// I had to get the handle this way because all I knew about the third party
// window was the title, not the process name or anything...
IntPtr hWnd = FindWindowEx(IntPtr.Zero, IntPtr.Zero, null, title);

// Now that I have a handle to the login window I used another windows API
// call to get the process ID.

// This windows API call gives me the Process ID as an out parameter and returns
// the thread ID of the window. I don't use the thread it, but maybe you can...
uint loginWindowProcId;
uint loginWindowThreadId = GetWindowThreadProcessId(hWnd, out loginWindowProcId);

// now I can just use .NET to find the Process for me...
Process loginWindowProcess = null;

if (0 != loginWindowProcId)
{
  // get the process object
  loginWindowProcess = Process.GetProcessById((int)loginWindowProcId);

  // This right here is why I wanted the Process structure. It takes a
  // little while for the client software to load and be ready. So here
  // you wait for the window to be idle so you know it has loaded and can
  // receive user input, or in this case keys from "SendKeys".
  loginWindowProcess.WaitForInputIdle();

  // I use yet another windows API call to make sure that the login window
  // is currently in the foreground. This ensures that the keys are sent
  // to the right window. Use the handle that we started with.
  SetForegroundWindow(hWnd);

  // Now send the password to the window. In my case, the user name is 
  // always there from my windows credentials. So normally I would type in the
  // password and press ENTER to login. But here I'll use SendKeys to mimic my
  // behavior.
  SendKeys.SendWait(password);   // send password string
  SendKeys.SendWait("{ENTER}");  // send ENTER key

  // Now the client should be logging in for you! : )

  // IMPORTANT NOTE
  // If you are using a console application like I am, you must add a reference to
  // System.Windows.Forms to your project and put "using System.Windows.Forms;" in
  // your code. This is required to use the "SendKeys" function.
  //
  // Also this code is just for my testing (quick and dirty), you will want to write 
  // more checks and catch errors and such. You should probably give the 
  // WaitForInputIdle a timeout etc...
}
.

도움이 되었습니까?

해결책

프로세스를 시작하고 완전히 시작될 때까지 기다릴 수있는 Process.WaitForInputIdle을 확인할 수 있습니다. 간단한 예입니다.

http://msdn.microsoft.com / ko / library / xb73d10t % 28v= vs.71 % 29.aspx

다른 팁

그것을 보는 것을 시도하십시오 : http://www.acoolsip.com/a-cool-blog/science-technology/151-ssending-commands-to-independent-windows.html

링크를 사용하여 창이 표시되고 메시지 (링크에서도)

를 확인할 수 있습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top