Hi!
I'm trying rewrite xCmd which can start a process on a remote machine. Basically it installs itself as a service on the target computer and then starts the requested process. Everything is working fine, but i noticed an error. xCmd is communicating through pipes, and it uses WriteFile(). My problem is, that if i run my API (or the originally, both produce this error), then for the first time it will start the requested process, but if i start it one more time, then it will "freeze out" at this line:
WriteFile( hCommandPipe, &msg, sizeof(msg), &dwTemp, NULL );
WriteFile
didn't returns any errorcode, the program just stops here. I can't even close cmd window. I can only close this, when i close on the target computer the service.
Can anyone help me to solve this? It's really annoying and i have no idea :(
Here is the function which isn't working properly:
BOOL ExecuteRemoteCommand()
{
DWORD dwTemp = 0;
xCmdMessage msg;
xCmdResponse response;
::ZeroMemory( &msg, sizeof(msg) );
::ZeroMemory( &response, sizeof(response) );
FillMessage( &msg );
// Send message to service
WriteFile( hCommandPipe, &msg, sizeof(msg), &dwTemp, NULL );
// Connects to remote pipes (stdout, stdin, stderr)
if ( ConnectToRemotePipes( 5, 1000 ) )
{
StdOutput( _T("Ok\n\n") );
// Waiting for response from service
ReadFile( hCommandPipe, &response, sizeof(response), &dwTemp, NULL );
}
else
StdOutput( _T("Failed\n\n") );
if ( response.dwErrorCode == 0 )
_tprintf( _T("\nRemote command returned %d(0x%X)\n"),
response.dwReturnCode,
response.dwReturnCode );
else
_tprintf( _T("\nRemote command failed to start. Returned error code is %d(0x%X)\n"),
response.dwErrorCode,
response.dwErrorCode );
return TRUE;
}
Thanks in advance!
kampi