wasSharpNET – Rev 27

Subversion Repositories:
Rev:
///////////////////////////////////////////////////////////////////////////
//  Copyright (C) Wizardry and Steamworks 2017 - License: GNU GPLv3      //
//  Please see: http://www.gnu.org/licenses/gpl.html for legal details,  //
//  rights of fair usage, the disclaimer and warranty conditions.        //
///////////////////////////////////////////////////////////////////////////

using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;

namespace wasSharpNET.Platform.Windows
{
    public static class Utilities
    {
        public static bool ElevatePrivileges()
        {
            try
            {
                // Create an elevated process with the original arguments.
                var info = new ProcessStartInfo(Assembly.GetEntryAssembly().Location,
                    string.Join(@" ", Environment.CommandLine.Split(' ').Skip(1)))
                {
                    Verb = "runas" // indicates to elevate privileges
                };

                var process = new System.Diagnostics.Process
                {
                    EnableRaisingEvents = true, // enable WaitForExit()
                    StartInfo = info
                };

                process.Start();
                process.WaitForExit();
            }
            catch (Exception)
            {
                return false;
            }

            return true;
        }

        public static bool isWindows()
        {
            return Environment.OSVersion.Platform.Equals(PlatformID.Win32NT) ||
                   Environment.OSVersion.Platform.Equals(PlatformID.Win32S) ||
                   Environment.OSVersion.Platform.Equals(PlatformID.Win32Windows) ||
                   Environment.OSVersion.Platform.Equals(PlatformID.WinCE);
        }
    }
}

Generated by GNU Enscript 1.6.5.90.