WinForms/Console application on Mono, how to know it runs as root
- by Lex Li-MSFT
As we can execute such executables in two ways, such as "sudo mono test.exe", and "mono test.exe".
Now I want to know how to detect whether this application is running as root inside the application itself.
I tried to check user name like below and see whether they equal to "root",
Thread.CurrentPrincipal.Identity.Name
Process.GetCurrentProcess().StartInfo.UserName
AppDomain.CurrentDomain.ApplicationIdentity.FullName
The first two are empty strings always, while the third throws NullReferenceException.
Please advise if this is doable on Mono 2.6.