Skip to content
This repository was archived by the owner on May 10, 2021. It is now read-only.

Commit 7c99435

Browse files
committed
Fixed TerrariaPatcher will now run as admin on windows vista/7.
1 parent eb7c019 commit 7c99435

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

TerrariaPatcher/Program.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
using System.IO;
55
using System.Linq;
66
using System.Net;
7+
using System.Reflection;
78
using System.Runtime.InteropServices;
89
using System.Security.Cryptography;
10+
using System.Security.Principal;
911

1012
namespace 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)

0 commit comments

Comments
 (0)