wasSharpNET
/Platform/Windows/Utilities.cs |
@@ -0,0 +1,44 @@ |
/////////////////////////////////////////////////////////////////////////// |
// 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; |
} |
} |
} |