This repository was archived by the owner on May 10, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change 44using System . IO ;
55using System . Linq ;
66using System . Net ;
7+ using System . Reflection ;
78using System . Runtime . InteropServices ;
89using System . Security . Cryptography ;
10+ using System . Security . Principal ;
911
1012namespace TerrariaPatcher
1113{
@@ -24,6 +26,17 @@ private static void Main(string[] args)
2426 {
2527 try
2628 {
29+ if ( Environment . OSVersion . Version . Major >= 6 && ! IsAdministrator ( ) )
30+ {
31+ Console . WriteLine ( "TerrariaPatcher requires admin privileges." ) ;
32+
33+ var selfProc = new Process ( ) ;
34+ selfProc . StartInfo . FileName = Assembly . GetExecutingAssembly ( ) . Location ;
35+ selfProc . StartInfo . Verb = "runas" ;
36+ selfProc . Start ( ) ;
37+ return ;
38+ }
39+
2740 if ( ! File . Exists ( AssemblyName + ".exe" ) )
2841 {
2942 Output ( AssemblyName + ".exe not found" ) ;
@@ -127,6 +140,13 @@ private static void Main(string[] args)
127140 Console . ReadLine ( ) ;
128141 }
129142
143+ public static bool IsAdministrator ( )
144+ {
145+ var identity = WindowsIdentity . GetCurrent ( ) ;
146+ var principal = new WindowsPrincipal ( identity ) ;
147+ return principal . IsInRole ( WindowsBuiltInRole . Administrator ) ;
148+ }
149+
130150 private static void Output ( string str )
131151 {
132152 if ( str . Length < 1 )
You can’t perform that action at this time.
0 commit comments