function Wait-ForUserInput {
Write-Host "Press Enter to execute" -ForegroundColor Green
Write-Host "Or 0 to return" -ForegroundColor Green
$key = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
if ($key.Character -eq "0") {
Clear-Host
return # Возвращение в меню
} elseif ($key.Character -eq "`r") {
Start-Sleep -Seconds 1
Write-Host
& $script # Вызов функции
Read-Host "Press Enter to continue"
Clear-Host
return
}
}
$filesScriptPath = "$env:APPDATA\Microsoft\Windows\Start Menu\Programs\Startup"
$filePath = "$filesScriptPath\aria2.vbs"
@"
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "aria2c.exe --dir=%USERPROFILE%\Downloads --enable-rpc=true --rpc-allow-origin-all=true --rpc-listen-all=true --rpc-listen-port=6800 --rpc-secret=12345 -D", 0
Set WshShell = Nothing
"@ | Set-Content -Path $filePath
Start-Process -FilePath $filePath
if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
$scriptPath = $MyInvocation.MyCommand.Path
$arguments = "-NoProfile -ExecutionPolicy Bypass -File `"$scriptPath`""
Start-Process powershell -ArgumentList $arguments -Verb RunAs
Exit
}
function Get-VersionsFromGitHub {
$url = "https://github.com/abbodi1406/vcredist/releases"
$response = Invoke-WebRequest -Uri $url
$versions = $response.Content | Select-String -Pattern "v\d+\.\d+\.\d+" -AllMatches | ForEach-Object { $_.Matches.Value }
return $versions
}
function Get-MaxVersion {
param (
[string[]]$versions
)
$maxVer = "v0.00.0"
foreach ($version in $versions) {
if ($version -match "v(\d{1,2})\.(\d{1,2})\.(\d{1,2})") {
$currentVer = "v$($matches[1]).$($matches[2]).$($matches[3])"
if ($currentVer -gt $maxVer) {
$maxVer = $currentVer
}
}
}
return $maxVer
}
$versions = Get-VersionsFromGitHub
$latestVersion = Get-MaxVersion -versions $versions
Write-Output "Max version product: $latestVersion"
Invoke-WebRequest -Uri "https://github.com/abbodi1406/vcredist/releases/download/$latestVersion/VisualCppRedist_AIO_x86_x64.exe" -OutFile ".\VisualCppRedist_AIO_x86_x64.exe"
Start-Process -FilePath ".\VisualCppRedist_AIO_x86_x64.exe" -ArgumentList "/y" -Wait
Remove-Item -Path ".\VisualCppRedist_AIO_x86_x64.exe"
pause
exit