Libin TK
Libin TK

Reputation: 1497

How do I restart computer using C# on EC2 Ubuntu Server?

I am running a C# Console Application on AWS EC2 instance with Ubuntu. I want to restart the computer from my Application using C#. Is there is any way that I can execute sudo reboot from C#?

Thanks in advance.

Upvotes: 0

Views: 2346

Answers (1)

Libin TK
Libin TK

Reputation: 1497

It works using the below code.

Process process = new Process();
process.StartInfo.FileName = "/usr/bin/sudo";
process.StartInfo.Arguments = "/sbin/shutdown -r now";
process.Start();

Upvotes: 2

Related Questions