@kinlion: it's nice that you found an alternate way, but why do you think it would be better to use? Direct API usage allows to interpret possible error reasons at a fine level, while your example, well, runs. You can't evaluate if its failing because a driver blocks the reboot, or shutdown is prohibited for your privileges, or ...