| | |
Crazy-Weird-Makes no sense?
![]() |
Hello guys. I made a simple program that works like command prompt. You insert a command, it inserts it into system();
why i do this? because im also adding my own commands. so before it goes into system. it checks first if its one of my newly made commands.
Whats the problem?
Well i was trying out a simple thing:
start notepad.exe
but when i got to:
taskkill /IM notepad.exe
it crashed?!!
So i tryed other things, if i do taskkill for anything EXEPT notepad.exe it works and doesent crash.
WTF is the problem?!!? please help. Tyvm guys.
why i do this? because im also adding my own commands. so before it goes into system. it checks first if its one of my newly made commands.
Whats the problem?
Well i was trying out a simple thing:
start notepad.exe
but when i got to:
taskkill /IM notepad.exe
it crashed?!!
So i tryed other things, if i do taskkill for anything EXEPT notepad.exe it works and doesent crash.
WTF is the problem?!!? please help. Tyvm guys.
Don't know what the problem is. Use your compiler's debugger and single-step through the code. Maybe it has a problem with the "/IM" parameter. Maybe that parameter should follow notepad.exe.
The most important thing in the Olympic Games is not to win but to take part, just as the most important thing in life is not the triumph but the struggle. The essential thing is not to have conquered but to have fought well.
-Pierre de Coubertin, The Olympic Creed Inspired by Bishop Ethelbert
-Pierre de Coubertin, The Olympic Creed Inspired by Bishop Ethelbert
•
•
•
•
Don't know what the problem is. Use your compiler's debugger and single-step through the code. Maybe it has a problem with the "/IM" parameter. Maybe that parameter should follow notepad.exe.
Maybe i'll bring it to visual studio to debug.
Ok let me explain this more...
Im making a sort-of remote computer control. Im not adding GUI yet, but i wanted at least to have control to the CMD. because you can do allot from the CMD. so im doing this with a predefined winsock class i found.
I made this same program before and it worked. But i wanted it to be easier to add commands. So i made a class for it. In this class it would connect to the client. The server sends info to the client, the client takes that and puts it into system(); then it sends back "Done".
This all works for EVERY COMMAND POSSIBLE exept for "taskkill /IM notoepad.exe"
could it possible be because i use a config.ini file to get the ip? may it not have closed correctly? Heres how i get the ip:
then i plug that ip so i can connect to it.
I dont know why every command works fine exept one. Its really weird. Thanks for your help again.
Im making a sort-of remote computer control. Im not adding GUI yet, but i wanted at least to have control to the CMD. because you can do allot from the CMD. so im doing this with a predefined winsock class i found.
C++ Syntax (Toggle Plain Text)
#pragma once #include "Winsock2.h" const int STRLEN = 256; class Socket { public: Socket(); ~Socket(); bool SendData( char* ); bool RecvData( char*, int ); void CloseConnection(); char* GetMessage(); protected: WSADATA wsaData; SOCKET mySocket; SOCKET myBackup; SOCKET acceptSocket; sockaddr_in myAddress; }; class ServerSocket : public Socket { public: void Listen(); void Bind( int port ); void StartHosting( int port ); }; class ClientSocket : public Socket { public: void ConnectToServer( const char *ipAddress, int port ); }; Socket::Socket() { if( WSAStartup( MAKEWORD(2, 2), &wsaData ) != NO_ERROR ) { cerr << "Socket Initialization: Error with WSAStartup\n"; system("pause"); WSACleanup(); exit(10); } //Create a socket mySocket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); if ( mySocket == INVALID_SOCKET ) { cerr << "Socket Initialization: Error creating socket" << endl; system("pause"); WSACleanup(); exit(11); } myBackup = mySocket; } Socket::~Socket() { WSACleanup(); } bool Socket::SendData( char *buffer ) { send( mySocket, buffer, strlen( buffer ), 0 ); return true; } bool Socket::RecvData( char *buffer, int size ) { int i = recv( mySocket, buffer, size, 0 ); buffer[i] = '\0'; return true; } void Socket::CloseConnection() { closesocket( mySocket ); mySocket = myBackup; } void ServerSocket::StartHosting( int port ) { Bind( port ); Listen(); } void ServerSocket::Listen() { if ( listen ( mySocket, 1 ) == SOCKET_ERROR ) { cerr << "ServerSocket: Error listening on socket\n"; system("pause"); WSACleanup(); exit(15); } acceptSocket = accept( myBackup, NULL, NULL ); while ( acceptSocket == SOCKET_ERROR ) { acceptSocket = accept( myBackup, NULL, NULL ); } mySocket = acceptSocket; } void ServerSocket::Bind( int port ) { myAddress.sin_family = AF_INET; myAddress.sin_addr.s_addr = inet_addr( "0.0.0.0" ); myAddress.sin_port = htons( port ); if ( bind ( mySocket, (SOCKADDR*) &myAddress, sizeof( myAddress) ) == SOCKET_ERROR ) { cerr << "ServerSocket: Failed to connect\n"; system("pause"); WSACleanup(); exit(14); } } void ClientSocket::ConnectToServer( const char *ipAddress, int port ) { myAddress.sin_family = AF_INET; myAddress.sin_addr.s_addr = inet_addr( ipAddress ); myAddress.sin_port = htons( port ); if ( connect( mySocket, (SOCKADDR*) &myAddress, sizeof( myAddress ) ) == SOCKET_ERROR ) { cerr << "ClientSocket: Failed to connect\n"; system("pause"); WSACleanup(); exit(13); } }
I made this same program before and it worked. But i wanted it to be easier to add commands. So i made a class for it. In this class it would connect to the client. The server sends info to the client, the client takes that and puts it into system(); then it sends back "Done".
This all works for EVERY COMMAND POSSIBLE exept for "taskkill /IM notoepad.exe"
could it possible be because i use a config.ini file to get the ip? may it not have closed correctly? Heres how i get the ip:
C++ Syntax (Toggle Plain Text)
char ip[256]; ifstream fin("config.ini"); if(!fin) sprintf(ip,"127.0.0.1"); // default ip (Loopback) else { fin.getline(ip,256); fin.close(); }
then i plug that ip so i can connect to it.
I dont know why every command works fine exept one. Its really weird. Thanks for your help again.
I never figured out how to use Dev-C++ debugger either -- I always use VC++ because it has such a great debugger. In your programs you may have to use two debugging sessions -- one for client and another for server. With VC++ I've done that successfully quite a few times.
As for your problem: Sorry, but I have no idea what's wrong.
As for your problem: Sorry, but I have no idea what's wrong.
The most important thing in the Olympic Games is not to win but to take part, just as the most important thing in life is not the triumph but the struggle. The essential thing is not to have conquered but to have fought well.
-Pierre de Coubertin, The Olympic Creed Inspired by Bishop Ethelbert
-Pierre de Coubertin, The Olympic Creed Inspired by Bishop Ethelbert
![]() |
Other Threads in the C++ Forum
- Previous Thread: The big Jop and The " WiNnEr "
- Next Thread: Where to go now?
Views: 468 | Replies: 7
| Thread Tools | Search this Thread |
Tag cloud for C++
6 algorithm array arrays assignment beginner binary c++ c++borland c/c++ calculator char class classes code compile compiler constructor conversion convert count delete dll dynamic encryption error file files filestream forms fstream function functions game givemetehcodez graph graphics gui homework iamthwee input int integer lazy link linker list loop loops map math matrix member memory network newbie number object objects opengl operator output parameter pointer pointers problem program programming project qt random read reading recursion recursive reference return server sort spoonfeeding string strings struct student studio template templates text time tree variable vc++ vector video visual win32 window windows winsock wxwidgets






