User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 456,433 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,648 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 1379 | Replies: 9
Reply
Join Date: Jul 2007
Posts: 2
Reputation: ElieK is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
ElieK ElieK is offline Offline
Newbie Poster

C++ system()

  #1  
Jul 10th, 2007
#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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Mar 2007
Location: Honduras
Posts: 1,407
Reputation: Nichito is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 26
Featured Poster
Nichito's Avatar
Nichito Nichito is offline Offline
Nearly a Posting Virtuoso

Re: C++ system()

  #2  
Jul 10th, 2007
first of all... what exactly do you want this for?
-->sometimes i wanna take my toaster in a bath<--
Reply With Quote  
Join Date: Jul 2007
Posts: 2
Reputation: ElieK is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
ElieK ElieK is offline Offline
Newbie Poster

Re: C++ system()

  #3  
Jul 10th, 2007
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
Last edited by ElieK : Jul 10th, 2007 at 10:16 pm.
Reply With Quote  
Join Date: Mar 2007
Location: Honduras
Posts: 1,407
Reputation: Nichito is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 26
Featured Poster
Nichito's Avatar
Nichito Nichito is offline Offline
Nearly a Posting Virtuoso

Re: C++ system()

  #4  
Jul 10th, 2007
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...
-->sometimes i wanna take my toaster in a bath<--
Reply With Quote  
Join Date: Apr 2004
Location: Tracy
Posts: 744
Reputation: Killer_Typo will become famous soon enough Killer_Typo will become famous soon enough 
Rep Power: 7
Solved Threads: 32
Killer_Typo's Avatar
Killer_Typo Killer_Typo is offline Offline
Master Poster

Re: C++ system()

  #5  
Jul 11th, 2007
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.
!!!!! WARNING YOUR COMPUTER MAY BE INFECTED WITH SPYWARE!!!! PAY AN OVER PRICED AMMOUNT TO HAVE SOMTHING FIXED WE PLACED THERE IN THE FIRST PLACE!!!!!!!!!

sound familiar, know how to block yourself and keep yourself clean.
_____________________
http://www.lavasoftusa.com/ -->adaware
http://www.safer-networking.org/en/index.html -->spybot S&D
http://www.javacoolsoftware.com/spywareblaster.html -->spywareblaster
http://www.javacoolsoftware.com/spywareguard.html -->spywareguard
_____________________
and dont forget to spread the reputation to those that deserve!
Reply With Quote  
Join Date: Jul 2007
Posts: 2
Reputation: Abhishek_jn is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Abhishek_jn Abhishek_jn is offline Offline
Newbie Poster

Question Re: C++ system()

  #6  
Jul 11th, 2007
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
Reply With Quote  
Join Date: Apr 2004
Location: Tracy
Posts: 744
Reputation: Killer_Typo will become famous soon enough Killer_Typo will become famous soon enough 
Rep Power: 7
Solved Threads: 32
Killer_Typo's Avatar
Killer_Typo Killer_Typo is offline Offline
Master Poster

Re: C++ system()

  #7  
Jul 11th, 2007
Originally Posted by Abhishek_jn View Post
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

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.
!!!!! WARNING YOUR COMPUTER MAY BE INFECTED WITH SPYWARE!!!! PAY AN OVER PRICED AMMOUNT TO HAVE SOMTHING FIXED WE PLACED THERE IN THE FIRST PLACE!!!!!!!!!

sound familiar, know how to block yourself and keep yourself clean.
_____________________
http://www.lavasoftusa.com/ -->adaware
http://www.safer-networking.org/en/index.html -->spybot S&D
http://www.javacoolsoftware.com/spywareblaster.html -->spywareblaster
http://www.javacoolsoftware.com/spywareguard.html -->spywareguard
_____________________
and dont forget to spread the reputation to those that deserve!
Reply With Quote  
Join Date: Jul 2007
Posts: 2
Reputation: Abhishek_jn is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Abhishek_jn Abhishek_jn is offline Offline
Newbie Poster

Re: C++ system()

  #8  
Jul 11th, 2007
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
Reply With Quote  
Join Date: Mar 2007
Location: Honduras
Posts: 1,407
Reputation: Nichito is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 26
Featured Poster
Nichito's Avatar
Nichito Nichito is offline Offline
Nearly a Posting Virtuoso

Re: C++ system()

  #9  
Jul 12th, 2007
question: could this shutdown be executed through internet?
-->sometimes i wanna take my toaster in a bath<--
Reply With Quote  
Join Date: Feb 2006
Location: UK
Posts: 468
Reputation: Bench has a spectacular aura about Bench has a spectacular aura about Bench has a spectacular aura about 
Rep Power: 5
Solved Threads: 42
Bench's Avatar
Bench Bench is offline Offline
Posting Pro in Training

Re: C++ system()

  #10  
Jul 12th, 2007
Originally Posted by Abhishek_jn View Post
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
Last edited by Bench : Jul 12th, 2007 at 9:17 pm.
¿umop apisdn upside down?
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 1:31 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC