Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Other Forums > Chit-Chat


Chit-Chat Relax for a bit and have a general conversation (off topic is allowed!) with other members. Please be polite and respect your fellow members.

Reply
 
Thread Tools Display Modes
Old 26th August 2005, 05:32 PM   (permalink)
Default c++ hidden?

i need to write a program that will shutdown a computer on the network.
i know how to do it and what to do but i need to run the program secretly.
just like how viruses do it you dont know there running but they are. how do i do this.
__________________
when you post that reply, im just kidding.
danielsmusic is offline   Reply With Quote
Old 27th August 2005, 12:13 AM   (permalink)
Default

Iiiiiish... What are you planning to do with this?...

You realize this is a touchy subject?...
Joel Rainville is offline   Reply With Quote
Old 27th August 2005, 12:23 PM   (permalink)
Default

its not a virus if thats what you think :lol:

i need to shutdown my own computer from my sisters, but i don't want to see the program running.


i know you can use the shutdown command in com prompt but it don't work.
__________________
when you post that reply, im just kidding.
danielsmusic is offline   Reply With Quote
Old 27th August 2005, 09:09 PM   (permalink)
Default

while remote shutdown is the topic i need to know why this code don't work properly
Code:
char *com;
cin >> com;
cout << "you entered " << com;
it prints only ONE word eg: i type "hello my name is daniel" it will print "hello"
__________________
when you post that reply, im just kidding.
danielsmusic is offline   Reply With Quote
Old 28th August 2005, 12:55 AM   (permalink)
Exo
Default

First of all, you create a pointer to a char type. You cannot store actual data in a pointer, it can only be used to ... well ... point to somewhere in memory... It's VERY strange your above code even returned a word...


So you need to make an array of char's to store your string...

Secondly, it's dangerous to use cin that way to read a string!
there is no length checking that way - if you have a 20byte array, and the user enters more then 20 characters then you're getting into a situation wich ANSI like to call 'undefined behaviour' (mostly a crash)...
Use getline() member of istream, it gets rid of your original problem too, it keeps reading till it gets and EOL character (enter)...

For example:

Code:
char com[30];         //a buffer for 30 characters

cin.getline(com, 30); //read a line from cin - only store 30 characters , the rest is truncated
cout << "You entered " << com;
Exo is offline   Reply With Quote
Old 28th August 2005, 01:07 AM   (permalink)
Default

i have always been using char * and never had a problem
the code you posted didnt work i did a screenshot.

btw: it is not a DOS program just a console
Attached Images
File Type: jpg console.jpg (26.0 KB, 82 views)
__________________
when you post that reply, im just kidding.
danielsmusic is offline   Reply With Quote
Old 28th August 2005, 01:11 AM   (permalink)
Default

the code isnt as important as the fact i need to hide it. do i do it in the regestry?
__________________
when you post that reply, im just kidding.
danielsmusic is offline   Reply With Quote
Old 28th August 2005, 01:16 AM   (permalink)
Exo
Default

It's not because you didn't have problems with it yet that it's the right way to do it...

When you create a pointer, it points to some random memory position. When you write to it the data will be stored on the position the pointer points to, wich is NOT your memory...

If it works then you're just lucky that spot is unused at that time, but another application, or part of your own may be residing at that position...

You allways need to allocate a real variable first, then you can point at it as much as you like...

Code:
char *pCh;         // a pointer to a char - it points to a random position - writing to it is NOT allowed
char MyString[10];   //an array of 10 bytes

pCh = &MyString;   //assing the ADRESS of MyString to the pointer pCh - Now the pointer points to a valid memory position
As for the getline() solution - it should work - post your complete code rather then a screenshot of the output.
Exo is offline   Reply With Quote
Old 28th August 2005, 01:17 AM   (permalink)
Exo
Default

Quote:
Originally Posted by danielsmusic
the code isnt as important as the fact i need to hide it. do i do it in the regestry?
I don't know how to 'hide' a program, i never had the need to, sorry.
Exo is offline   Reply With Quote
Old 28th August 2005, 01:20 AM   (permalink)
Default

i don't like posting code it look so messy and i never comment bad programmer i am ops: but it is important.

Code:
#include <iostream>
#include <windows.h>
#include <string>
#include <fstream>
using namespace std;

int main(int argc, char *argv[])
{
	string who_to_send;
	string addon = "\\C\\TMP.TMP";
	string addbe = "\\\\";
	cout << "Type the computer name to send to:";
	cin >> who_to_send;
	addbe.append(who_to_send);
	string final = addbe.append(addon);	
	cout << "\nHas this computer got the reciver program installed(1 = yes, 0 = no):";
	int yesno = 0;
	cin >> yesno;
	ofstream file;
	cout << "Loading please wait ...";
	file.open(final.data(), fstream::out);
	if(file.fail())
	{
		cout << "\nLoading failed!";
		cout << "\nThis program will ternamate in:3";
		Sleep(1000);
		cout << "\b \b";
		cout << "2";
		Sleep(1000);
		cout << "\b \b";
		cout << "1";
		Sleep(1000);
		return 0;
	}
	if(!yesno)
	{
		fstream file2;
		cout << "\nCopying...";
		file2.open(argv[0], fstream::in);
		string copy1;
		copy1.append("copy ");
		copy1.append(argv[0]);
		copy1.append(" ");
		copy1.append(who_to_send);
		copy1.append("\\\\C\\remote_shutdown.exe");
		cout << copy1;
		system(copy1.data());
		
	}
	cout << "\nPlease enter the command you want to send:";
	char * com;         
	cin >> com; 
	cout << "You entered " << com; 
	file << com;
	file.close();
	cout << "\n\n\n";
	return 0;
}
__________________
when you post that reply, im just kidding.
danielsmusic is offline   Reply With Quote
Old 28th August 2005, 01:24 AM   (permalink)
Exo
Default

That's the old code :lol: ....
I mean post the new one with getline(), it should work, if it doesnt you made an error.
Exo is offline   Reply With Quote
Old 28th August 2005, 01:30 AM   (permalink)
Default

you see what i mean about poorly written :wink:

Code:
#include <iostream>
#include <windows.h>
#include <string>
#include <fstream>
using namespace std;

int main(int argc, char *argv[])
{
	string who_to_send;
	string addon = "\\C\\TMP.TMP";
	string addbe = "\\\\";
	cout << "Type the computer name to send to:";
	cin >> who_to_send;
	addbe.append(who_to_send);
	string final = addbe.append(addon);	
	cout << "\nHas this computer got the reciver program installed(1 = yes, 0 = no):";
	int yesno = 0;
	cin >> yesno;
	ofstream file;
	cout << "Loading please wait ...";
	file.open(final.data(), fstream::out);
	if(file.fail())
	{
		cout << "\nLoading failed!";
		cout << "\nThis program will ternamate in:3";
		Sleep(1000);
		cout << "\b \b";
		cout << "2";
		Sleep(1000);
		cout << "\b \b";
		cout << "1";
		Sleep(1000);
		return 0;
	}
	if(!yesno)
	{
		fstream file2;
		cout << "\nCopying...";
		file2.open(argv[0], fstream::in);
		string copy1;
		copy1.append("copy ");
		copy1.append(argv[0]);
		copy1.append(" ");
		copy1.append(who_to_send);
		copy1.append("\\\\C\\remote_shutdown.exe");
		cout << copy1;
		system(copy1.data());
		
	}
	cout << "\nPlease enter the command you want to send:";
	char com[30];         
	cin.getline(com, 30);  
	cout << "You entered " << com; 
	file << com;
	file.close();
	cout << "\n\n\n";
	return 0;
}
__________________
when you post that reply, im just kidding.
danielsmusic is offline   Reply With Quote
Old 28th August 2005, 01:37 AM   (permalink)
Exo
Default

Right, it seems there is still a EOL character in the stream that wasn't extracted from a previous input action..

try adding a "cin.get()" in front of the "getline()" command.
Exo is offline   Reply With Quote
Old 28th August 2005, 01:45 AM   (permalink)
Default

finally, it worked why does the EOL ch float and where was it?
__________________
when you post that reply, im just kidding.
danielsmusic is offline   Reply With Quote
Old 28th August 2005, 01:49 AM   (permalink)
Exo
Default

It's because of this:

Code:
cout << "\nHas this computer got the reciver program installed(1 = yes, 0 = no):"; 
int yesno = 0; 
cin >> yesno;
You type a number (1 or 0) and then press the enter key, this puts the number + a EOL (enter) in the stream
The overloaded operator 'istream:perator >>()' only reads your number from the stream and stores it in your variable yesno.
The EOL however stays in the stream - When you call the 'getline()' it will return immediately because the first character it reads is a EOL.

the extra istream::get() gets the EOL out of the stream.
Exo is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes




All times are GMT. The time now is 02:29 PM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.