mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2025-01-17 18:27:42 -06:00
Simplified Admin Check and Added Code Comments (#1938)
- Simplified the admin check by filtering the "WindowsIdentity" class for owner value and comparing against admin value - Removed the need for an if admin check by moving its commands under the if not admin check. - Added code comments
This commit is contained in:
parent
794d390a7f
commit
eec184ee81
@ -44,17 +44,8 @@ $sync.version = "#{replaceme}"
|
|||||||
$sync.configs = @{}
|
$sync.configs = @{}
|
||||||
$sync.ProcessRunning = $false
|
$sync.ProcessRunning = $false
|
||||||
|
|
||||||
$currentPid = [System.Security.Principal.WindowsIdentity]::GetCurrent()
|
# If script isn't running as admin, show error message and quit
|
||||||
$principal = new-object System.Security.Principal.WindowsPrincipal($currentPid)
|
If (([Security.Principal.WindowsIdentity]::GetCurrent()).Owner.Value -ne "S-1-5-32-544")
|
||||||
$adminRole=[System.Security.Principal.WindowsBuiltInRole]::Administrator
|
|
||||||
|
|
||||||
|
|
||||||
if ($principal.IsInRole($adminRole))
|
|
||||||
{
|
|
||||||
$Host.UI.RawUI.WindowTitle = $myInvocation.MyCommand.Definition + "(Admin)"
|
|
||||||
clear-host
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
Write-Host "===========================================" -Foregroundcolor Red
|
Write-Host "===========================================" -Foregroundcolor Red
|
||||||
Write-Host "-- Scripts must be run as Administrator ---" -Foregroundcolor Red
|
Write-Host "-- Scripts must be run as Administrator ---" -Foregroundcolor Red
|
||||||
@ -62,3 +53,7 @@ else
|
|||||||
Write-Host "===========================================" -Foregroundcolor Red
|
Write-Host "===========================================" -Foregroundcolor Red
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Set PowerShell window title
|
||||||
|
$Host.UI.RawUI.WindowTitle = $myInvocation.MyCommand.Definition + "(Admin)"
|
||||||
|
clear-host
|
||||||
|
Loading…
Reference in New Issue
Block a user