| |

VerySource

 Forgot password?
 Register
Search
View: 670|Reply: 2

Please heroes, how can I use my WIN32 program to control keyboard input of other DOS programs?

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 Invalid IP Address

Post time: 2020-1-30 13:40:01
| Show all posts |Read mode
The questions are as follows.
There is already a DOS program (it may also be a program for the windows console), there is no source code,
I want to call up this dos executable program through my program. After getting up, my program simulates the keyboard of the system and gives it input, as if it is running by itself, and the customer types information from the keyboard.
Sorry, I have n’t touched this kind of stuff before, please give me a method, the more detailed the better, it is better to tell me how to hide its window, thank you very much, online etc.
Reply

Use magic Report

0

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-3-30 17:45:01
| Show all posts
Redirection, give you an example:
char cmdbuffer [1024];
HANDLE hReadPipe;
HANDLE hReadPipe2;
HANDLE hWritePipe;
HANDLE hWritePipe2;

DWORD __stdcall ThreadFun (void * pVoid)
{
HWND hwnd = * ((HWND *) pVoid);
Ranch
SECURITY_ATTRIBUTES sat;
STARTUPINFO startupinfo;
PROCESS_INFORMATION pinfo;
BYTE buffer [1024];
DWORD byteRead;
CString rString;
Ranch
Ranch
sat.nLength = sizeof (SECURITY_ATTRIBUTES);
sat.bInheritHandle = true;
sat.lpSecurityDescriptor = NULL;
if (! CreatePipe (&hReadPipe,&hWritePipe,&sat, NULL))
{
MessageBox (NULL, "Create Pipe Error!", "Error!", MB_OK);
return 0;
}
if (! CreatePipe (&hReadPipe2,&hWritePipe2,&sat, NULL))
{
MessageBox (NULL, "Create Pipe2 Error!", "Error!", MB_OK);
return 0;
}
startupinfo.cb = sizeof (STARTUPINFO);
GetStartupInfo (&startupinfo);
startupinfo.hStdError = hWritePipe;
startupinfo.hStdOutput = hWritePipe;
startupinfo.hStdInput = hReadPipe2;
startupinfo.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
startupinfo.wShowWindow = SW_HIDE;
if (! CreateProcess (NULL, "c:\\winnt\\system32\\cmd.exe", NULL, NULL, TRUE, NULL, NULL, NULL,&startupinfo,&pinfo))
{
MessageBox (NULL, "create process error!", "Error!", MB_OK);
return 0;
}
CloseHandle (hWritePipe);
CloseHandle (hReadPipe2);
CloseHandle (pinfo.hThread);
CloseHandle (pinfo.hProcess);
Ranch
while (true)
{
RtlZeroMemory (buffer, 1024);
if (ReadFile (hReadPipe, buffer, 1023,&byteRead, NULL) == NULL)
break;
// buffer is the content displayed on the screen
}
CloseHandle (hReadPipe);
CloseHandle (hWritePipe2);
return 0;
}

// Create a thread:
HANDLE hThread = NULL;
hThread = CreateThread (NULL, 0, ThreadFun,&m_hWnd, 0,&dwThreadId); // m_hWnd This parameter is determined by your needs
if (hThread == NULL)
{
MessageBox ("CreateThread failed.", "Main", MB_OK);
}
else
{
CloseHandle (hThread);
}

// Write a command to the consel program:
strcpy (cmdbuffer, "dir");
strcat (cmdbuffer, "\r\n"); // There must be a carriage return and line feed
WriteFile (hWritePipe2, cmdbuffer, strlen (cmdbuffer),&byteRead, NULL);
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 Invalid IP Address

 Author| Post time: 2020-4-28 12:45:01
| Show all posts
Thank youmoon_archer!
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list