Original Post
http://msdn.microsoft.com/en-us/library/ms682499(VS.85).aspx The MSDN sample project hooks into a application and redirects stdin and stdout to locally created handles connected to read/write pipes. If I run "cmd.exe" and I redirect the stdin and out to a local pipe then I can run commands from cmd.exe shell by sending them to the pipe. Every dos command runs fine exept the windows 32 applications. If I try to run "calc.exe" the process is being spawned (in taskman) but not shown on the desktop. Following code sends calc.exe to the console
void WriteToPipe(void)
{
DWORD dwRead, dwWritten;
CHAR chBuf[BUFSIZE];
BOOL bSuccess = FALSE;
WriteFile(g_hChildStd_IN_Wr, "calc.exe\r\n", 10, &dwWritten, NULL);
for (;;)
{
bSuccess = ReadFile(g_hInputFile, chBuf, BUFSIZE, &dwRead, NULL);
if ( ! bSuccess || dwRead == 0 ) break;
bSuccess = WriteFile(g_hChildStd_IN_Wr, chBuf, dwRead, &dwWritten, NULL);
if ( ! bSuccess ) break;
}
if ( ! CloseHandle(g_hChildStd_IN_Wr) )
ErrorExit(TEXT("StdInWr CloseHandle"));
}
If after sending the "calc.exe" trough the pipe I send another 3 pairs of CRLF in the same pipe then the calc.exe is being shown on the desktop. This happen with any GUI application.
void WriteToPipe(void)
{
DWORD dwRead, dwWritten;
CHAR chBuf[BUFSIZE];
BOOL bSuccess = FALSE;
WriteFile(g_hChildStd_IN_Wr, "calc.exe\r\n", 10, &dwWritten, NULL);
WriteFile(g_hChildStd_IN_Wr, "\r\n", 2, &dwWritten, NULL);
WriteFile(g_hChildStd_IN_Wr, "\r\n", 2, &dwWritten, NULL);
WriteFile(g_hChildStd_IN_Wr, "\r\n", 2, &dwWritten, NULL); // calc is shown
for (;;)
{
bSuccess = ReadFile(g_hInputFile, chBuf, BUFSIZE, &dwRead, NULL);
if ( ! bSuccess || dwRead == 0 ) break;
bSuccess = WriteFile(g_hChildStd_IN_Wr, chBuf, dwRead, &dwWritten, NULL);
if ( ! bSuccess ) break;
}
if ( ! CloseHandle(g_hChildStd_IN_Wr) )
ErrorExit(TEXT("StdInWr CloseHandle"));
}
Also if I close the writing handle right away the GUII spwans on the desktop right away bu there is no more a handle to send any more commands...
void WriteToPipe(void)
{
DWORD dwRead, dwWritten;
CHAR chBuf[BUFSIZE];
BOOL bSuccess = FALSE;
WriteFile(g_hChildStd_IN_Wr, "calc.exe\r\n", 10, &dwWritten, NULL);
CloseHandle(g_hChildStd_IN_Wr) ; // // calc is shown
Any ideas what the heck is this.