mirror of
https://github.com/PowerShell/openssh-portable.git
synced 2025-07-31 01:35:11 +02:00
Check if Powershell is running in admin mode before running script (#493)
This commit is contained in:
parent
bbb500a639
commit
794bf53f49
@ -3,6 +3,13 @@
|
|||||||
# @manojampalam - removed ntrights.exe dependency
|
# @manojampalam - removed ntrights.exe dependency
|
||||||
# @bingbing8 - removed secedit.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
|
$scriptpath = $MyInvocation.MyCommand.Path
|
||||||
$scriptdir = Split-Path $scriptpath
|
$scriptdir = Split-Path $scriptpath
|
||||||
|
|
||||||
@ -48,6 +55,7 @@ finally {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Fix the registry permissions
|
# Fix the registry permissions
|
||||||
|
If ($PSVersiontable.PSVersion.Major -le 2) {$PSScriptRoot = Split-Path -Parent $MyInvocation.MyCommand.Path}
|
||||||
Import-Module $PSScriptRoot\OpenSSHUtils -Force
|
Import-Module $PSScriptRoot\OpenSSHUtils -Force
|
||||||
Enable-Privilege SeRestorePrivilege | out-null
|
Enable-Privilege SeRestorePrivilege | out-null
|
||||||
|
|
||||||
|
@ -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
|
$scriptdir = Split-Path $scriptpath
|
||||||
$etwman = Join-Path $scriptdir "openssh-events.man"
|
$etwman = Join-Path $scriptdir "openssh-events.man"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user