![]() |
![]() |
![]() |
|
|
|||||||
| 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. |
|
|
Thread Tools | Display Modes |
|
|
(permalink) |
|
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. |
|
|
|
|
|
|
(permalink) |
|
Iiiiiish... What are you planning to do with this?...
You realize this is a touchy subject?... |
|
|
|
|
|
|
(permalink) |
|
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. |
|
|
|
|
|
|
(permalink) |
|
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;
__________________
when you post that reply, im just kidding. |
|
|
|
|
|
|
(permalink) |
|
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; |
|
|
|
|
|
|
(permalink) |
|
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
__________________
when you post that reply, im just kidding. |
|
|
|
|
|
|
(permalink) |
|
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. |
|
|
|
|
|
|
(permalink) |
|
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 |
|
|
|
|
|
|
(permalink) | |
|
Quote:
|
||
|
|
|
|
|
(permalink) |
|
i don't like posting code it look so messy and i never comment bad programmer i am
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. |
|
|
|
|
|
|
(permalink) |
|
That's the old code :lol: ....
I mean post the new one with getline(), it should work, if it doesnt you made an error. |
|
|
|
|
|
|
(permalink) |
|
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. |
|
|
|
|
|
|
(permalink) |
|
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. |
|
|
|
|
|
|
(permalink) |
|
finally, it worked why does the EOL ch float and where was it?
__________________
when you post that reply, im just kidding. |
|
|
|
|
|
|
(permalink) |
|
It's because of this:
Code:
cout << "\nHas this computer got the reciver program installed(1 = yes, 0 = no):"; int yesno = 0; cin >> yesno; The overloaded operator 'istream: 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. |
|
|
|
|