mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2025-04-01 17:12:09 +00:00
Update start.ps1
fix logic of permissions elevation process
This commit is contained in:
parent
1ae16f6f38
commit
841eb454ed
@ -39,6 +39,7 @@ $sync.version = "#{replaceme}"
|
|||||||
$sync.configs = @{}
|
$sync.configs = @{}
|
||||||
$sync.ProcessRunning = $false
|
$sync.ProcessRunning = $false
|
||||||
|
|
||||||
|
|
||||||
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
|
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
|
||||||
Write-Output "Winutil needs to be run as Administrator. Attempting to relaunch."
|
Write-Output "Winutil needs to be run as Administrator. Attempting to relaunch."
|
||||||
$argList = @()
|
$argList = @()
|
||||||
@ -46,21 +47,23 @@ if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]:
|
|||||||
$PSBoundParameters.GetEnumerator() | ForEach-Object {
|
$PSBoundParameters.GetEnumerator() | ForEach-Object {
|
||||||
$argList += if ($_.Value -is [switch] -and $_.Value) {
|
$argList += if ($_.Value -is [switch] -and $_.Value) {
|
||||||
"-$($_.Key)"
|
"-$($_.Key)"
|
||||||
|
} elseif ($_.Value -is [array]) {
|
||||||
|
"-$($_.Key) $($_.Value -join ',')"
|
||||||
} elseif ($_.Value) {
|
} elseif ($_.Value) {
|
||||||
"-$($_.Key) `"$($_.Value)`""
|
"-$($_.Key) '$($_.Value)'"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$script = if ($MyInvocation.MyCommand.Path) {
|
$script = if ($PSCommandPath) {
|
||||||
"& { & '$($MyInvocation.MyCommand.Path)' $argList }"
|
"& { & `"$($PSCommandPath)`" $($argList -join ' ') }"
|
||||||
} else {
|
} else {
|
||||||
"iex '& { $(irm https://github.com/ChrisTitusTech/winutil/releases/latest/download/winutil.ps1) } $argList'"
|
"&([ScriptBlock]::Create((irm https://github.com/ChrisTitusTech/winutil/releases/latest/download/winutil.ps1))) $($argList -join ' ')"
|
||||||
}
|
}
|
||||||
|
|
||||||
$powershellcmd = if (Get-Command pwsh -ErrorAction SilentlyContinue) { "pwsh" } else { "powershell" }
|
$powershellcmd = if (Get-Command pwsh -ErrorAction SilentlyContinue) { "pwsh" } else { "powershell" }
|
||||||
$processCmd = if (Get-Command wt.exe -ErrorAction SilentlyContinue) { "wt.exe" } else { $powershellcmd }
|
$processCmd = if (Get-Command wt.exe -ErrorAction SilentlyContinue) { "wt.exe" } else { $powershellcmd }
|
||||||
|
|
||||||
Start-Process $processCmd -ArgumentList "$powershellcmd -ExecutionPolicy Bypass -NoProfile -Command $script" -Verb RunAs
|
Start-Process $processCmd -ArgumentList "$powershellcmd -ExecutionPolicy Bypass -NoProfile -Command `"$script`"" -Verb RunAs
|
||||||
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user