Comment 9 for bug 435422

Revision history for this message
Eran C (shush6) wrote :

Marcel is right that you can't shut down the system using the shutdown command without root privileges. GNOME panel shut down the system by contacting a daemon with root privileges via DBUS.

So in Gnome (and I think it will also work in KDE) you can shutdown the system by calling the shutdown method on this DBUS Service: org.freedesktop.PowerManagement

code should look something like these:

objectPath = '/org/freedesktop/PowerManagement'
busName = 'org.freedesktop.PowerManagement'
bus = dbus.SessionBus()
pm = bus.get_object(busName, objectPath)
pm.Shutdown()

other methods available are:Hibernate() ,Suspend(), Reboot()

haven't tested it yet because then I couldn't complete this message :) but it should work... problem is that it might not work on other Desktop envierments.