Repository navigation
Expand file tree
/
Copy pathScriptAtualizarWinrar
More file actions
63 lines (54 loc) · 2 KB
/
Copy pathScriptAtualizarWinrar
File metadata and controls
63 lines (54 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Definir URL de Download e Caminho de Download
$winrarUrl = "https://www.rarlab.com/rar/winrar-x64-701br.exe"
$downloadPath = Join-Path -Path $env:TEMP -ChildPath "winrar.exe"
# Função para baixar o instalador do WinRAR
function Download-WinRAR {
Write-Output "Baixando o WinRAR..."
try {
Invoke-WebRequest -Uri $winrarUrl -OutFile $downloadPath -ErrorAction Stop
Write-Output "Download concluído: $downloadPath"
} catch {
Write-Output "Erro ao baixar o WinRAR: $_"
exit 1
}
}
# Função para desinstalar o WinRAR se ele estiver instalado
function Uninstall-WinRAR {
$uninstallKey = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\WinRAR archiver"
if (Test-Path $uninstallKey) {
$uninstallString = (Get-ItemProperty -Path $uninstallKey).UninstallString
if ($uninstallString) {
Write-Output "Desinstalando a versão atual do WinRAR..."
Start-Process -FilePath "cmd.exe" -ArgumentList "/c $uninstallString /S" -NoNewWindow -Wait
Start-Sleep -Seconds 5
}
}
}
# Função para instalar o WinRAR
function Install-WinRAR {
if (Test-Path $downloadPath) {
Write-Output "Instalando a nova versão do WinRAR..."
Start-Process -FilePath $downloadPath -ArgumentList "/S" -NoNewWindow -Wait
} else {
Write-Output "O instalador do WinRAR não foi encontrado em $downloadPath"
exit 1
}
}
# Função para limpar o instalador baixado
function Clean-Up {
if (Test-Path $downloadPath) {
Write-Output "Limpando o instalador baixado..."
Remove-Item -Path $downloadPath -Force
} else {
Write-Output "O instalador do WinRAR já foi removido ou não foi encontrado em $downloadPath"
}
}
# Baixar o instalador do WinRAR
Download-WinRAR
# Desinstalar o WinRAR se estiver instalado
Uninstall-WinRAR
# Instalar a nova versão do WinRAR
Install-WinRAR
# Limpar o instalador baixado
Clean-Up
Write-Output "Atualização do WinRAR concluída com sucesso."