Search code examples
c#linuxmonoraspbianopenbox

Closing window manager & powering off from C#/Mono program


I'm developing a program in mono/C# which will run on a Linux embedded platform with a touch-screen.

I've installed OpenBox in top of Raspbian, because this will run in "kiosk mode" and I'm trying to keep it as simple as possible.

I was planning to have two options in the program:

  1. option to shutdown the computer
  2. option to close the windows manager (openbox) and return to the terminal

For the first option I've tried using:

shutdown
poweroff
systcl poweroff

commands but all require special privileges, so I'm not sure on what would be the best approach. Should I create a bash script with root privileges and run this script from the program?

For the second option, I don't even know how to start. I've configured openbox to be able to close it from the keyboard through Ctrl + Alt + Backspace, but I know how to close it from the program. I've tried using SendKeys with that key combination but does not work.

I've also tried the solution here using DBUS for C# but I've issues compiling it.

Could you please give any advice?


Solution

  • You can set your sudo program up to let a user run a program without any password. Add to your visudo file:

    <username-or-ALL> ALL=(ALL) NOPASSWD:/sbin/poweroff
    

    See this maybe

    If I were you, I would reboot after setting up and before testing.