コード例 #1
0
        // Does this cover sudo?
        public static bool IsRunningAsRoot()
        {
            var runner   = new ExternalCommandRunner();
            var username = runner.RunExternalCommand("whoami");

            return(username != null?username.Contains("root") : false);
        }
コード例 #2
0
 public static bool IsRunningAsRoot()
 {
     if (ExternalCommandRunner.RunExternalCommand("whoami", string.Empty, out string username, out string _) == 0)
     {
         return(username.Trim().Equals("root"));
     }
     return(false);
 }
コード例 #3
0
 public static string GetOsVersion()
 {
     if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
     {
         return(System.Environment.OSVersion.VersionString);
     }
     else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
     {
         return(ExternalCommandRunner.RunExternalCommand("uname", "-r"));
     }
     return("");
 }
コード例 #4
0
 public static string GetOsName()
 {
     if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
     {
         return(Helpers.RuntimeString());
     }
     else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
     {
         return(ExternalCommandRunner.RunExternalCommand("uname", "-s"));
     }
     return("");
 }
コード例 #5
0
 public static bool IsRunningAsRoot()
 {
     var username = "******";
     try
     {
         username = ExternalCommandRunner.RunExternalCommand("whoami");
     }
     catch (Exception)
     {
         Log.Fatal("Couldn't run 'whoami' to determine root.");
     }
     return username != null ? username.Equals("root") : false;
 }
コード例 #6
0
 public static string GetOsName()
 {
     if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
     {
         return(AsaHelpers.GetPlatformString());
     }
     else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
     {
         if (ExternalCommandRunner.RunExternalCommand("uname", "-s", out string StdOut, out string _) == 0)
         {
             return(StdOut);
         }
     }
     return("");
 }