restart / shutdown ubuntu

Hi,
I would like to be able to shut down the computer from within my application and this is what i do so far:

  
system ("sudo shutdown -h now");  

it generally works but I have to input my root password manually.- Is there any way taht i can just directly shut it down?

thanks

Ok, i solved it, you have to do some terminal stuff to allow non root users to shut the computer down, basically i did what is described here in the sudo section:
http://www.spencerstirling.com/computer-…-tdown.html

then you can use it like this:

  
system ("shutdown -h now");  

hope that helps anybody in the future :slight_smile:

In Ubuntu, you could always use gksudo (or kdesudo for KDE) at the beginning of the system() session to grab Super User rights through a graphical interface. For vanilla Ubuntu, which uses GNOME, use gksudo, and for Kubuntu, use kdesudo. You would accomplish this like so:

  
  
  
system("gksudo shutdown -h now");  
  
  

well I needed it to just shut down without any interface or callback. If you can live with a GUI confirmation window your solution is easier then writing custom rights i guess :slight_smile:

One way might be to have a password file that is read by the program (via ofxXmlSettings or some other file reader) to get your password, and then do this:
(Although the sudo input prompt may be staggered to block password injections this way…)

  
  
string cmd = string("sudo shutdown -h now\n") + myPassword;  
system(cmd.c_str());