Replace custom admin directive with PowerShell standard directive
This commit is contained in:
parent
5a91475dd8
commit
da0d1d6d7a
5 changed files with 3177 additions and 9 deletions
|
|
@ -7,6 +7,7 @@ using System.Management.Automation;
|
|||
using System.Management.Automation.Runspaces;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using LANCommander.SDK.Abstractions;
|
||||
using LANCommander.SDK.Factories;
|
||||
|
|
@ -71,8 +72,8 @@ namespace LANCommander.SDK.PowerShell
|
|||
{
|
||||
Contents = File.ReadAllText(path);
|
||||
|
||||
if (Contents.StartsWith("# Requires Admin"))
|
||||
RunAsAdmin = true;
|
||||
if (RequiresAdmin())
|
||||
AsAdmin();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
|
@ -81,8 +82,8 @@ namespace LANCommander.SDK.PowerShell
|
|||
{
|
||||
Contents = contents;
|
||||
|
||||
if (Contents.StartsWith("# Requires Admin"))
|
||||
RunAsAdmin = true;
|
||||
if (RequiresAdmin())
|
||||
AsAdmin();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
|
@ -150,6 +151,13 @@ namespace LANCommander.SDK.PowerShell
|
|||
return this;
|
||||
}
|
||||
|
||||
private bool RequiresAdmin()
|
||||
{
|
||||
var pattern = @"^#(\s?Requires\s?Admin)|(Requires -RunAsAdministrator)\s*$";
|
||||
|
||||
return Regex.IsMatch(Contents, pattern);
|
||||
}
|
||||
|
||||
public async Task<T> ExecuteAsync<T>()
|
||||
{
|
||||
T result = default;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue