Hi All,
I've spent my Saturday writing a program which now works perfectly well and I spent this morning making it look nice.
However, I want to make it run at the right time automatically, instead of waiting for a user to start it when needed.
The basic problem is, that in a WinPE environment an exe is running. Unfortunately it would need critical input, which must be inputted perfectly. So, I wrote a program which gets the data and sends it to the other app, by bringing it to the front and presses the keys needed using SendInput().
However, this program should wait for it's cue, then get on the inputting part. It's cue should be the point where the program waits for the first user input with this displayed on the last line:
Text:
My question is: how to listen and check whether the last line displayed is "Text:"?
I've tried with AttachConsole(), but for some reason it opens a new console window. I checked and the PID I'm using is the console window's, so I don't know why that happens.
The few lines I'm trying with:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
HWND hwnd = FindWindow(NULL, "Administrator: Command Prompt");
SetForegroundWindow(hwnd);
SetFocus(hwnd);
DWORD process_id;
GetWindowThreadProcessId(hwnd, &process_id);
AttachConsole(process_id);
char lastline[5];
COORD pos={1,1};
DWORD dwChars;
ReadConsoleOutputCharacter(GetStdHandle(STD_OUTPUT_HANDLE), lastline, 5, pos, &dwChars)
lastline[dwChars]='\0';
cout << dwChars << endl;
FreeConsole();
|
Please don't criticize the first line. I know it can be ambiguous, but I modified it, so it can be tested at home by anyone using an admin prompt. When actually using it, the exe name will be in the title, so it will be unique.
Thanks in advance!