Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

C++ system()

Status
Not open for further replies.

ElieK54

Programmer
Jul 10, 2007
1
CA
#include <stdlib.h>

int main(void){

system("shutdown -r -f -m \\192.168.1.104 -t 60");

return 0;
}


This command closes a computer on the network, i tried it and it works fine. All i need is to my program to run it so I can run it with the IP adress i will give him. I have been working on this for days....i looked in _popen _pclose but i don't think that's the way. When i run it, it opens about 50 windows of command prompt and then close them. If someone can tell me why my code isn't working i'd be very happy.

Thank you
Elie
 
I don't know the syntax for the shutdown command, but when you type this at the command prompt, does it work properly?
Code:
shutdown -r -f -m \\192.168.1.104 -t 60

BTW, in C/C++ the '\' character is an escape character, so if you want "\" in your string, you need to escape it first, i.e. "\\".
So your code should probably be:
Code:
system("shutdown -r -f -m \\\\192.168.1.104 -t 60");
 
See also InitiateSystemShutdown/InitiateSystemShutdownEx Windows API functions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top