WinForms/Console application on Mono, how to know it runs as root

Posted by Lex Li-MSFT on Stack Overflow See other posts from Stack Overflow or by Lex Li-MSFT
Published on 2010-04-11T03:59:06Z Indexed on 2010/04/11 4:03 UTC
Read the original article Hit count: 329

Filed under:
|
|

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.

© Stack Overflow or respective owner

Related posts about mono

Related posts about opensuse