mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2024-12-29 01:11:30 -06:00
Compare commits
5 Commits
d2b06a6852
...
0c1ab9d8ea
Author | SHA1 | Date | |
---|---|---|---|
|
0c1ab9d8ea | ||
|
31be3b01c6 | ||
|
a9a6d7cf64 | ||
|
1bc32e0aff | ||
|
6a871b1feb |
@ -39,32 +39,26 @@ $sync.version = "#{replaceme}"
|
|||||||
$sync.configs = @{}
|
$sync.configs = @{}
|
||||||
$sync.ProcessRunning = $false
|
$sync.ProcessRunning = $false
|
||||||
|
|
||||||
|
# Store latest script URL in variable.
|
||||||
|
$latestScript = "https://github.com/ChrisTitusTech/winutil/releases/latest/download/winutil.ps1"
|
||||||
|
|
||||||
|
# Check if script is running as Administrator
|
||||||
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 = @()
|
|
||||||
|
|
||||||
$PSBoundParameters.GetEnumerator() | ForEach-Object {
|
# Partial rollback from #2648, changed irm and iex to Invoke-RestMethod and Invoke-Expression.
|
||||||
$argList += if ($_.Value -is [switch] -and $_.Value) {
|
$script = if ($MyInvocation.MyCommand.Path) { "& '" + $MyInvocation.MyCommand.Path + "'" } else { "Invoke-RestMethod '$latestScript' | Invoke-Expression"}
|
||||||
"-$($_.Key)"
|
|
||||||
} elseif ($_.Value) {
|
|
||||||
"-$($_.Key) `"$($_.Value)`""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$script = if ($MyInvocation.MyCommand.Path) {
|
|
||||||
"& { & '$($MyInvocation.MyCommand.Path)' $argList }"
|
|
||||||
} else {
|
|
||||||
"iex '& { $(irm https://github.com/ChrisTitusTech/winutil/releases/latest/download/winutil.ps1) } $argList'"
|
|
||||||
}
|
|
||||||
|
|
||||||
$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 new process with elevated privileges
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Logging
|
||||||
$dateTime = Get-Date -Format "yyyy-MM-dd_HH-mm-ss"
|
$dateTime = Get-Date -Format "yyyy-MM-dd_HH-mm-ss"
|
||||||
|
|
||||||
$logdir = "$env:localappdata\winutil\logs"
|
$logdir = "$env:localappdata\winutil\logs"
|
||||||
|
Loading…
Reference in New Issue
Block a user