0

我想从命令行读取字符串。我打开了一些在命令行中运行的程序,我必须等待该程序进程。所以,我不知道什么时候处理成功。如果不能从命令中读取字符串,我就不能输入下一个命令。这是我在命令中运行程序 unhidden.bat 并发送 Y 进行处理的代码。

DWORD WINAPI unhidden(LPVOID lp)
{
   //ShellExecute(NULL, L"open", L"C:/unhidden.exe", NULL, NULL, SW_SHOWNORMAL);
    system("C:/unhidden.bat");
   return 0;
}

int run_unhidden(){
    AllocConsole() ;
    AttachConsole( GetCurrentProcessId() ) ;
    freopen( "CON", "w", stdout ) ;

    HANDLE hConIn = GetStdHandle(STD_INPUT_HANDLE);
    HANDLE hConOut = GetStdHandle(STD_OUTPUT_HANDLE);
    DWORD dwTmp;

    INPUT_RECORD ir[5];

    CreateThread(NULL, 0, unhidden,(LPDWORD)0, 0, &dwTmp);

    Sleep( 1000 );

    ir[0].EventType = KEY_EVENT;
    ir[0].Event.KeyEvent.bKeyDown = TRUE;
    ir[0].Event.KeyEvent.dwControlKeyState = 0;
    ir[0].Event.KeyEvent.uChar.UnicodeChar = 'y';
    ir[0].Event.KeyEvent.wRepeatCount = 1;
    ir[0].Event.KeyEvent.wVirtualKeyCode = 'Y';
    ir[0].Event.KeyEvent.wVirtualScanCode = MapVirtualKey('Y', MAPVK_VK_TO_VSC);

    ir[1].EventType = KEY_EVENT;
    ir[1].Event.KeyEvent.bKeyDown = TRUE;
    ir[1].Event.KeyEvent.dwControlKeyState = 0;
    ir[1].Event.KeyEvent.uChar.UnicodeChar = VK_RETURN;
    ir[1].Event.KeyEvent.wRepeatCount = 1;
    ir[1].Event.KeyEvent.wVirtualKeyCode = VK_RETURN;
    ir[1].Event.KeyEvent.wVirtualScanCode = MapVirtualKey(VK_RETURN, MAPVK_VK_TO_VSC);

    ir[2].EventType = KEY_EVENT;
    ir[2].Event.KeyEvent.bKeyDown = FALSE;
    ir[2].Event.KeyEvent.dwControlKeyState = 0;
    ir[2].Event.KeyEvent.uChar.UnicodeChar = VK_RETURN;
    ir[2].Event.KeyEvent.wRepeatCount = 1;
    ir[2].Event.KeyEvent.wVirtualKeyCode = VK_RETURN;
    ir[2].Event.KeyEvent.wVirtualScanCode = MapVirtualKey(VK_RETURN, MAPVK_VK_TO_VSC);



    dwTmp = 0;
    WriteConsoleInput(hConIn, ir, 2, &dwTmp);

wprintf(GetCommandLine());

    Sleep( 1000 );



    ir[0].EventType = KEY_EVENT;
    ir[0].Event.KeyEvent.bKeyDown = TRUE;
    ir[0].Event.KeyEvent.dwControlKeyState = 0;
    ir[0].Event.KeyEvent.uChar.UnicodeChar = 'y';
    ir[0].Event.KeyEvent.wRepeatCount = 1;
    ir[0].Event.KeyEvent.wVirtualKeyCode = 'Y';
    ir[0].Event.KeyEvent.wVirtualScanCode = MapVirtualKey('Y', MAPVK_VK_TO_VSC);

    ir[1].EventType = KEY_EVENT;
    ir[1].Event.KeyEvent.bKeyDown = TRUE;
    ir[1].Event.KeyEvent.dwControlKeyState = 0;
    ir[1].Event.KeyEvent.uChar.UnicodeChar = VK_RETURN;
    ir[1].Event.KeyEvent.wRepeatCount = 1;
    ir[1].Event.KeyEvent.wVirtualKeyCode = VK_RETURN;
    ir[1].Event.KeyEvent.wVirtualScanCode = MapVirtualKey(VK_RETURN, MAPVK_VK_TO_VSC);


    ir[2].EventType = KEY_EVENT;
    ir[2].Event.KeyEvent.bKeyDown = FALSE;
    ir[2].Event.KeyEvent.dwControlKeyState = 0;
    ir[2].Event.KeyEvent.uChar.UnicodeChar = VK_RETURN;
    ir[2].Event.KeyEvent.wRepeatCount = 1;
    ir[2].Event.KeyEvent.wVirtualKeyCode = VK_RETURN;
    ir[2].Event.KeyEvent.wVirtualScanCode = MapVirtualKey(VK_RETURN, MAPVK_VK_TO_VSC);

     dwTmp = 0;
    WriteConsoleInput(hConIn, ir, 3, &dwTmp);
    wprintf(GetCommandLine());
     Sleep( 1000 );

它在控制台中显示如下

Do you want to process now (Y/N)?y "C:\Users\PKRU\documents\visual studio 2010\Projects\Virus Scan\Debug\Virus Scan .exe" You chose: y 
Please wait . . . 
"C:\Users\PKRU\documents\visual studio 2010\Projects\Virus Scan\Debug\Virus Scan .exe" Could Not Find N:\*.lnk 
N:\autorun.ini\*, Are you sure (Y/N)?

怎么读线

N:\autorun.ini*,您确定 (Y/N) 吗?

使用 MFC 将下一个键发送到控制台。如果我不知道它什么时候会显示这一行,那么我不能发送 Y 或 N 来编程

4

0 回答 0