s k
s k

Reputation: 5212

How to force reboot Raspberry PI using C#

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

Upvotes: 1

Views: 2914

Answers (2)

Dee
Dee

Reputation: 103

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.

Upvotes: 4

Andrius Bentkus
Andrius Bentkus

Reputation: 1392

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

Upvotes: 0

Related Questions