Skip to content

Commit

Permalink
windows install script
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszgasior committed Jun 23, 2024
1 parent 7244cac commit b1c6f61
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@ param (
[string]$version = "v0.1.0"
)

if (!([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
function Test-IsAdmin {
$currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
return $currentUser.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}

if (-not (Test-IsAdmin)) {
Write-Host "Script not running as Administrator. Restarting with elevated privileges..."

if ($PSVersionTable.PSEdition -eq "Core") {
$shell = "pwsh"
}
else {
$shell = "powershell"
}

$scriptPath = $MyInvocation.MyCommand.Path
Start-Process -FilePath $shell -ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"$scriptPath`"" -Verb RunAs

Start-Process -FilePath $shell -ArgumentList ("-NoProfile -ExecutionPolicy Bypass -File `"" + $($MyInvocation.MyCommand.Path) + "`"") -Verb RunAs
exit
}

Expand Down

0 comments on commit b1c6f61

Please sign in to comment.