Something like the function below will take care of the end of the Unix / Mono question. By the way, I didn’t actually collect or run this, but you get the point.
private bool AmIRoot()
{
string fileName = "blah.txt",
content = "";
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.EnableRaisingEvents=false;
proc.StartInfo.FileName = "whoami > " + fileName;
proc.StartInfo.Arguments = "";
proc.Start();
proc.WaitForExit();
StreamReader sr = new StreamReader(fileName);
content = sr.ReadLine();
sr.Close();
File.Delete(fileName);
if(content == "root")
return true;
else
return false;
}
source
share