Skip to content

Commit

Permalink
[BUG] Child processes won't elevate (#488), version 1.3.2.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Hofknecht committed Aug 12, 2023
1 parent 9683e5c commit 68258eb
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
1 change: 1 addition & 0 deletions Business/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ private static void Main(string[] args)
Config.SetFolderByWindowsContextMenu(args);
Config.LoadOrSetByUser();
Config.Initialize();
PrivilegeChecker.Initialize();

if (SingleAppInstance.Initialize())
{
Expand Down
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.3.2.4")]
[assembly: AssemblyFileVersion("1.3.2.4")]
[assembly: AssemblyVersion("1.3.2.6")]
[assembly: AssemblyFileVersion("1.3.2.6")]
9 changes: 8 additions & 1 deletion Utilities/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,16 +159,23 @@ internal static void ProcessStart(

try
{
string verb = string.Empty;
if (!PrivilegeChecker.IsCurrentUserInAdminGroup)
{
verb = "runas";
}

using Process p = new()
{

StartInfo = new ProcessStartInfo(fileName)
{
FileName = fileName,
Arguments = arguments,
WorkingDirectory = workingDirectory,
CreateNoWindow = createNoWindow,
UseShellExecute = true,
Verb = "runas",
Verb = verb,
},
};
p.Start();
Expand Down
29 changes: 29 additions & 0 deletions Utilities/PrivilegeChecker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// <copyright file="PrivilegeChecker.cs" company="PlaceholderCompany">
// Copyright (c) PlaceholderCompany. All rights reserved.
// </copyright>

namespace SystemTrayMenu.Utilities
{
using System.Linq;
using System.Security.Principal;

internal static class PrivilegeChecker
{
public static bool IsCurrentUserInAdminGroup { get; set; }

public static void Initialize()
{
// https://stackoverflow.com/questions/3600322/check-if-the-current-user-is-administrator
// https://learn.microsoft.com/en-us/troubleshoot/windows-server/identity/security-identifiers-in-windows
// S-1-5-32-544
// A built-in group. After the initial installation of the operating system,
// the only member of the group is the Administrator account.
// When a computer joins a domain, the Domain Admins group is added to
// the Administrators group. When a server becomes a domain controller,
// the Enterprise Admins group also is added to the Administrators group.
var principal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
var claims = principal.Claims;
IsCurrentUserInAdminGroup = claims.FirstOrDefault(c => c.Value == "S-1-5-32-544") != null;
}
}
}

0 comments on commit 68258eb

Please sign in to comment.