This repository has been archived by the owner on Feb 29, 2024. It is now read-only.
forked from SDUQD-SNA/SduNetCheckTool
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
在DNS更改页面增加了以管理员权限重启的按钮
- Loading branch information
Showing
4 changed files
with
123 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.Security.Principal; | ||
|
||
namespace SduNetCheckTool.Core.Utils | ||
{ | ||
public static class Identifier | ||
{ | ||
/// <summary> | ||
/// IsAdministrator | ||
/// </summary> | ||
/// <returns></returns> | ||
public static bool IsAdministrator() | ||
{ | ||
try | ||
{ | ||
WindowsIdentity current = WindowsIdentity.GetCurrent(); | ||
WindowsPrincipal windowsPrincipal = new(current); | ||
//WindowsBuiltInRole可以枚举出很多权限,例如系统用户、User、Guest等等 | ||
return windowsPrincipal.IsInRole(WindowsBuiltInRole.Administrator); | ||
} | ||
catch (Exception) | ||
{ | ||
// log | ||
return false; | ||
} | ||
} | ||
|
||
public static string ExePath => Process.GetCurrentProcess().MainModule.FileName ?? string.Empty; | ||
public static string StartupPath => AppDomain.CurrentDomain.BaseDirectory; | ||
|
||
public static string AppendQuotes(string value) => string.IsNullOrEmpty(value) ? string.Empty : $"\"{value}\""; | ||
|
||
|
||
public static void RebootAsAdmin() | ||
{ | ||
ProcessStartInfo startInfo = new() | ||
{ | ||
UseShellExecute = true, | ||
Arguments = "rebootas", | ||
WorkingDirectory = StartupPath, | ||
FileName = AppendQuotes(ExePath), | ||
Verb = "runas", | ||
}; | ||
try | ||
{ | ||
Process.Start(startInfo); | ||
Exit(); | ||
} | ||
catch { } | ||
} | ||
|
||
public static void Exit() | ||
{ | ||
//Application.Current.Shutdown(); | ||
Environment.Exit(0); | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters