How to force reboot Raspberry PI using C#

2.7k views Asked by At

Using Rasbian. My Console apps was launched using crontab

@reboot /home/pi/MyConsole.sh

The MyConsole.sh will then fire "sudo mono MyConsole.exe"

From time to time, when my apps received a "Reboot" command, I am trying to reboot the system using:

System.Diagnostics.Process.Start("sudo shutdown -r now");

But it doesn't work, I really have no clue after searching in the web for two days :(

Appreciate any help.

Thanks In Advance

2

There are 2 answers

0
Andrius Bentkus On

Add the user that is running to the power group (if such a user exists) or read this up: https://wiki.archlinux.org/index.php/allow_users_to_shutdown

1
Dee On

This is what I do and it works fine. The main app, as in your case, is also run with elevated privileges i.e. sudo...

System.Diagnostics.Process.Start(new ProcessStartInfo() {FileName = "sudo", Arguments = "reboot"});

I hope this helps.