fixed #1267: Don't run installer as admin if member of administrators group

This commit is contained in:
Jaex 2020-10-23 12:08:29 +03:00
parent b47687f9fe
commit d16dcaa9ce
2 changed files with 19 additions and 1 deletions

View file

@ -1229,6 +1229,24 @@ public static bool IsAdministrator()
}
}
public static bool IsMemberOfAdministratorsGroup()
{
try
{
using (WindowsIdentity identity = WindowsIdentity.GetCurrent())
{
WindowsPrincipal principal = new WindowsPrincipal(identity);
SecurityIdentifier sid = new SecurityIdentifier(WellKnownSidType.BuiltinAdministratorsSid, null);
return principal.UserClaims.Any(x => x.Value.Contains(sid.Value));
}
}
catch
{
}
return false;
}
public static string RepeatGenerator(int count, Func<string> generator)
{
string result = "";

View file

@ -168,7 +168,7 @@ private void RunInstaller()
psi.Arguments += " /VERYSILENT";
}
if (Helpers.IsDefaultInstallDir())
if (Helpers.IsDefaultInstallDir() && !Helpers.IsMemberOfAdministratorsGroup())
{
psi.Verb = "runas";
}