Demo-Console演示打开任意一个exe文件
-----------------------------------------------------------------------------------------------
#include <Windows.h>
#include <iostream>
#define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
using namespace std ;
DWORD WINAPI ClientThread(LPVOID lpParam) ;
HANDLE hThread ;
DWORD dwThread ;
void PrintChar(char *ch,UINT count,UINT x,UINT y)
{
HANDLE h=GetStdHandle(STD_OUTPUT_HANDLE);
COORD pos;
ULONG unuse;
pos.X=x;
pos.Y=y;
CONSOLE_SCREEN_BUFFER_INFO bInfo;
GetConsoleScreenBufferInfo(h, &bInfo );
WriteConsoleOutputCharacterA(h,ch,count,pos,&unuse);
}
int main()
{
char buffer[1024] ;
cout << "请输入exe的全路径:" ;
UINT ival ;
PrintChar("Exit - Esc",10,0,24) ;
hThread = CreateThread(NULL,0,ClientThread,NULL,0,&dwThread) ;
while(cin >> buffer)
{
ival = WinExec(buffer,SW_SHOW) ;
if(ival > 31)
cout << "执行成功" << endl ;
else if (ival == 0)
cout << "内存耗尽 returned value: 0" ;
else if (ival == ERROR_BAD_FORMAT)
cout << "无效的可执行文件" << endl ;
else if (ival == ERROR_FILE_NOT_FOUND)
cout << "未找到文件" << endl ;
else if (ival == ERROR_PATH_NOT_FOUND)
cout << "路径无效" << endl ;
}
}
DWORD WINAPI ClientThread(LPVOID lpParam)
{
while(1)
{
if(KEYDOWN(VK_ESCAPE))
system("taskkill /F /IM WinSock.exe") ;
}
}