Repository navigation
Expand file tree
/
Copy pathUpdate7Zip
More file actions
56 lines (48 loc) · 1.81 KB
/
Copy pathUpdate7Zip
File metadata and controls
56 lines (48 loc) · 1.81 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
# Função para obter a URL do instalador mais recente do 7-Zip
function Get-Latest7ZipUrl {
$webContent = Invoke-WebRequest -Uri "https://www.7-zip.org/download.html"
$links = $webContent.Links
foreach ($link in $links) {
if ($link.href -match '7z\d+-x64\.exe$') {
return "https://www.7-zip.org/$($link.href)"
}
}
throw "Não foi possível encontrar o URL do instalador mais recente do 7-Zip."
}
# Obtenha a URL do instalador mais recente
try {
$downloadUrl = Get-Latest7ZipUrl
Write-Output "URL do instalador mais recente do 7-Zip: $downloadUrl"
} catch {
Write-Error $_.Exception.Message
exit 1
}
# Defina o caminho do instalador
$installerPath = "$env:Temp\7zip.exe"
# Baixe o instalador
Write-Output "Baixando 7-Zip..."
Invoke-WebRequest -Uri $downloadUrl -OutFile $installerPath
# Feche o 7-Zip se estiver em execução
Write-Output "Fechando 7-Zip se estiver em execução..."
Stop-Process -Name "7zFM" -ErrorAction SilentlyContinue
# Desinstale a versão antiga do 7-Zip (se necessário)
Write-Output "Desinstalando a versão antiga do 7-Zip (se houver)..."
$app = Get-WmiObject -Class Win32_Product | Where-Object { $_.Name -like "7-Zip*" }
if ($app) {
$app.Uninstall()
Write-Output "Versão antiga do 7-Zip desinstalada."
} else {
Write-Output "Nenhuma versão antiga do 7-Zip encontrada."
}
# Instale a nova versão
Write-Output "Instalando a nova versão do 7-Zip..."
Start-Process -FilePath $installerPath -ArgumentList "/S" -Wait
# Verifique se a instalação foi bem-sucedida
if (Get-Command "C:\Program Files\7-Zip\7z.exe" -ErrorAction SilentlyContinue) {
Write-Output "7-Zip atualizado com sucesso."
} else {
Write-Error "Falha ao atualizar o 7-Zip."
}
# Limpe o instalador
Remove-Item -Path $installerPath
Write-Output "Instalador removido."