You're right the goto's weren't necessary. I rewrote it and now everything works perfectly. Here is the new code. Oh, and yes, I was thinking like wtf it's not making the jump so lets force it with a old school goto haha.
PHP Code:
// MHC-CM.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <windows.h>
#include <cstdlib>
int _tmain(int argc, _TCHAR* argv[])
{
// Stealth mode so we don't see the command prompt window
HWND stealth = FindWindowA("ConsoleWindowClass",NULL);
FreeConsole();
while(1)
{
//Cache Maintenance Window
HWND hWnd1 = FindWindow("TfrmConfirmCacheMaintenance","Confirmation");
//Purge Maintenance Window
HWND hWnd2 = FindWindow("TfrmConfirmCacheMaintenance","Confirmation");
Sleep(100);
//This portion checks for the Cache Maintenance Message Box
if(hWnd1)
{
//Cache Maintenance Window
DWORD ProcessID1;
GetWindowThreadProcessId( hWnd1, &ProcessID1 );
HANDLE Process1 = OpenProcess( PROCESS_ALL_ACCESS, FALSE, ProcessID1 );
if(Process1)
{
//Emulated keypresses
/*
keybd_event(VK_RIGHT, NULL, NULL, NULL);
keybd_event(VK_RIGHT, NULL, KEYEVENTF_KEYUP, NULL);
*/
keybd_event(VK_RETURN, NULL, NULL, NULL);
keybd_event(VK_RETURN, NULL, KEYEVENTF_KEYUP, NULL);
CloseHandle(Process1);
}
}
//This portion checks for the Purge Maintenance Message Box
else if(hWnd2)
{
//Purge Maintenance Window
DWORD ProcessID2;
GetWindowThreadProcessId( hWnd2, &ProcessID2 );
HANDLE Process2 = OpenProcess( PROCESS_ALL_ACCESS, FALSE, ProcessID2 );
if(Process2)
{
//Emulated keypresses
/*
keybd_event(VK_RIGHT, NULL, NULL, NULL);
keybd_event(VK_RIGHT, NULL, KEYEVENTF_KEYUP, NULL);
*/
keybd_event(VK_RETURN, NULL, NULL, NULL);
keybd_event(VK_RETURN, NULL, KEYEVENTF_KEYUP, NULL);
CloseHandle(Process2);
}
}
}
return 0;
}
Question I have, is this a win32 application, and does it contain a window or just a shell, I mean does the Windows command window pop up when u run it ?
Yes the command prompt window comes up, but I learned this little trick that hides it & it works flawlessly.
Code:
// Stealth mode so we don't see the command prompt window
HWND stealth = FindWindowA("ConsoleWindowClass",NULL);
FreeConsole();
You can see it used in my code above!
NOTE: I know both my window handles are the same, that's because I can't get the handle on the purge maintenance yet because I can't get it to come up atm. Just figured I would mention that if people are like wtf.. why are you doing the same thing twice haha. Once I get the class & title name then I'll update hWnd2 and voila!