egrath Posted June 20, 2005 Posted June 20, 2005 Hi,i currently try to write to a other's process standard input. I am using the OpenProcess Function and then the DuplicateHandle Function to get the Handle of the other's stdin.Below is my non-working code:#include <stdio.h>#include <stdlib.h>#include <windows.h>int main( int argc, char* argv[] ){ HANDLE hProcess, hMyProcess; HANDLE hInput; unsigned int nProcess; if( argc != 2 ) { fprintf( stderr, "illegal arg count\n" ); exit( -1 ); } else { nProcess = atoi( argv[1] ); } fprintf( stdout, "Attaching pro Process %d ... ", nProcess ); if(( hProcess = OpenProcess( PROCESS_ALL_ACCESS, TRUE, ( DWORD ) nProcess )) != NULL ) { fprintf( stdout, "OK\n" ); } else { fprintf( stdout, "FAILED\n" ); exit( -1 ); } hMyProcess = GetCurrentProcess(); fprintf( stdout, "Trying to get STDIN Handle from Process ... " ); if( ! DuplicateHandle( hProcess, GetStdHandle( STD_INPUT_HANDLE ), hMyProcess, &hInput, 0, TRUE, DUPLICATE_SAME_ACCESS )) { fprintf( stdout, "FAILED\n" ); fprintf( stdout, "%08X\n", GetLastError()); exit( -1 ); } else { fprintf( stdout, "OK\n" ); } CloseHandle( hInput ); return 0;}Does anyone see why this doesn't work? Do i have any logical errors?Thanks, Egon
egrath Posted June 27, 2005 Author Posted June 27, 2005 Hi,found out that it's impossible to connect to another's process stdin/stdout/stderr Handle when you are not the father of that process. It's a security thing.Egon
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now