new fix if there was a launch from the admin

Found an easier fix to fix a bug installing Spotify with administrator rights
This commit is contained in:
amd64fox
2022-02-07 00:16:04 +03:00
parent 9c22f6d34d
commit 7d7b197dd9
2 changed files with 10 additions and 60 deletions

View File

@@ -14,7 +14,6 @@ $chrome_elf_bak = "$spotifyDirectory\chrome_elf_bak.dll"
$upgrade_client = $false
$podcasts_off = $false
$spotx_new = $false
$run_as_admin = $false
$block_update = $false
$cache_install = $false
@@ -25,16 +24,6 @@ if (!($tsl_check -match '^tls12$' )) {
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
}
# Checking startup rights
[System.Security.Principal.WindowsPrincipal] $principal = [System.Security.Principal.WindowsIdentity]::GetCurrent()
$isUserAdmin = $principal.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)
if ($isUserAdmin) {
Write-Host 'Startup detected with administrator rights'`n
$run_as_admin = $true
}
Stop-Process -Name Spotify
Stop-Process -Name SpotifyWebHelper
@@ -216,24 +205,10 @@ if (-not $spotifyInstalled -or $upgrade_client) {
Remove-Item $spotifyDirectory -Include *chrome_elf* -Recurse -Force
}
# Correcting the error if the spotify installer was launched from the administrator
if ($run_as_admin) {
$apppath = 'powershell.exe'
$taskname = 'Spotify install'
$action = New-ScheduledTaskAction -Execute $apppath -Argument "-NoLogo -NoProfile -Command & `'$PWD\SpotifySetup.exe`'"
$trigger = New-ScheduledTaskTrigger -Once -At (Get-Date)
$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -WakeToRun
Register-ScheduledTask -Action $action -Trigger $trigger -TaskName $taskname -Settings $settings -Force | Write-Verbose
Start-ScheduledTask -TaskName $taskname
Start-Sleep -Seconds 2
Unregister-ScheduledTask -TaskName $taskname -Confirm:$false
Start-Sleep -Seconds 2
wait-process -name SpotifySetup
}
else {
Start-Process -FilePath $PWD\SpotifySetup.exe; wait-process -name SpotifySetup
}
# Client installation
Start-Process -FilePath explorer.exe -ArgumentList $PWD\SpotifySetup.exe
while (-not (get-process | Where-Object { $_.ProcessName -eq 'SpotifySetup' })) {}
wait-process -name SpotifySetup
Stop-Process -Name Spotify
Stop-Process -Name SpotifyWebHelper

View File

@@ -14,7 +14,6 @@ $chrome_elf_bak = "$spotifyDirectory\chrome_elf_bak.dll"
$upgrade_client = $false
$podcasts_off = $false
$spotx_new = $false
$run_as_admin = $false
$block_update = $false
$cache_install = $false
@@ -25,16 +24,6 @@ if (!($tsl_check -match '^tls12$' )) {
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
}
# Проверка прав запуска
[System.Security.Principal.WindowsPrincipal] $principal = [System.Security.Principal.WindowsIdentity]::GetCurrent()
$isUserAdmin = $principal.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)
if ($isUserAdmin) {
Write-Host 'Обнаружен запуск с правами администратора'`n
$run_as_admin = $true
}
Stop-Process -Name Spotify
Stop-Process -Name SpotifyWebHelper
@@ -215,26 +204,12 @@ if (-not $spotifyInstalled -or $upgrade_client) {
Start-Sleep -Seconds 1
Remove-Item $spotifyDirectory -Include *chrome_elf* -Recurse -Force
}
# Исправление ошибки, если установщик Spotify был запущен от администратора
if ($run_as_admin) {
$apppath = 'powershell.exe'
$taskname = 'Spotify install'
$action = New-ScheduledTaskAction -Execute $apppath -Argument "-NoLogo -NoProfile -Command & `'$PWD\SpotifySetup.exe`'"
$trigger = New-ScheduledTaskTrigger -Once -At (Get-Date)
$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -WakeToRun
Register-ScheduledTask -Action $action -Trigger $trigger -TaskName $taskname -Settings $settings -Force | Write-Verbose
Start-ScheduledTask -TaskName $taskname
Start-Sleep -Seconds 2
Unregister-ScheduledTask -TaskName $taskname -Confirm:$false
Start-Sleep -Seconds 2
wait-process -name SpotifySetup
}
else {
Start-Process -FilePath $PWD\SpotifySetup.exe; wait-process -name SpotifySetup
}
# Установка клиента
Start-Process -FilePath explorer.exe -ArgumentList $PWD\SpotifySetup.exe
while (-not (get-process | Where-Object { $_.ProcessName -eq 'SpotifySetup' })) {}
wait-process -name SpotifySetup
Stop-Process -Name Spotify
Stop-Process -Name SpotifyWebHelper
Stop-Process -Name SpotifyFullSetup