#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

first of all... what exactly do you want this for?

I'm en electrical engineer and i do energy efficiency project. We are doing a lot of schools and colleges these days and we wanted to be able to close computers at night or when necessary.

This is why i need to do this...

Hope you can help me

have you tried storing the ip address in a string, and then using it in the system call? BTW... you should try using a more specific title next time...

you dont need C++ to do this.

in fact running a shutdown on mass ammounts computers is better suited for a NT script.

you could just as easily write a bat file

shutdown -r -f -m \\192.168.1.104 -t 60

just open notepad, save as .bat and run it.

hey,
I tried with what you have said i saved the command in notepad as bat file then run it , i didnt get expected result ?
It is openning up a command prompt and the the command which i have saved

hey,
I tried with what you have said i saved the command in notepad as bat file then run it , i didnt get expected result ?
It is openning up a command prompt and the the command which i have saved

what do you mean by it is opening up the command prompt with the command you have entered?

it should open the prompt and run the command you have entered.

if that is what it is doing then it has worked :P

here is what i just did to test

open notepad > [Windows Key] + R
in the prompt type> Notepad
Press the [Enter] Key

type in the simple command

dir | more  
#the directory command piped through more
#piping through more allows the user to read a screenfull
#of information at a time

file>Save

File Type>All File Types

Name>anything you want.bat

(it is important to have the BAT extension)

run the file from anywhere (command prompt works best)

should get the directory contents of the current directory and stop at each screenful.

Sorry I interprete wrong :
what i understand that if i run the bat file then system gets shut down,
but it is just keep running the command prompt. shwing the command which i saved i.e. shutdown -r -f -m \\IP -t 60

question: could this shutdown be executed through internet?

Sorry I interprete wrong :
what i understand that if i run the bat file then system gets shut down,
but it is just keep running the command prompt. shwing the command which i saved i.e. shutdown -r -f -m \\IP -t 60

And what happens when you just type it in directly to the system's console?

FWIW, if the command you've got doesn't work when typed in directly, or run from a batch file, then wrapping it in C++ code isn't going to do any different.

You should visit a forum specific to the OS on which you're attempting to run the command - they might be better able to help you with the problem

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.