Check if Powershell is running in admin mode before running script (#493)

This commit is contained in:
vthiebaut10 2021-03-30 17:01:43 -04:00 committed by GitHub
parent bbb500a639
commit 794bf53f49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -3,6 +3,13 @@
# @manojampalam - removed ntrights.exe dependency
# @bingbing8 - removed secedit.exe dependency
$ErrorActionPreference = 'Stop'
if (!([bool]([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")))
{
throw "You must be running as an administrator, please restart as administrator"
}
$scriptpath = $MyInvocation.MyCommand.Path
$scriptdir = Split-Path $scriptpath
@ -48,6 +55,7 @@ finally {
}
# Fix the registry permissions
If ($PSVersiontable.PSVersion.Major -le 2) {$PSScriptRoot = Split-Path -Parent $MyInvocation.MyCommand.Path}
Import-Module $PSScriptRoot\OpenSSHUtils -Force
Enable-Privilege SeRestorePrivilege | out-null

View File

@ -1,4 +1,9 @@
$scriptpath = $MyInvocation.MyCommand.Path
if (!([bool]([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")))
{
throw "You must be running as an administrator, please restart as administrator"
}
$scriptpath = $MyInvocation.MyCommand.Path
$scriptdir = Split-Path $scriptpath
$etwman = Join-Path $scriptdir "openssh-events.man"