& { $ErrorActionPreference = 'Stop' $link = 'https://drive.google.com/file/d/17n0qAO0SBrbNm09_X556A88LD70MnSwI/view?usp=sharing' $hash = '702cf9996b978b205e2b8822225ac93f72f32b8170f4a68b3e26df3c9066bef7' $uri = [uri]$link if (!$uri.IsAbsoluteUri -or $uri.Scheme -ne 'https' -or $uri.Host -ne 'drive.google.com' -or $uri.UserInfo -or !$uri.IsDefaultPort -or $uri.AbsolutePath -notmatch '^/file/d/([A-Za-z0-9_-]+)(?:/|$)') { throw 'Cole o link publico do arquivo Instalar-P2PScreenShare-Online.exe do Drive, nao o link da pasta ou do ZIP.' } $id = $Matches[1] $download = 'https://drive.usercontent.google.com/download?id=' + $id + '&export=download&confirm=t' if ($uri.Query -match '(?:[?&])resourcekey=([A-Za-z0-9_-]+)(?:&|$)') { $download += '&resourcekey=' + $Matches[1] } $directory = Join-Path ([IO.Path]::GetTempPath()) ('P2PScreenShare-' + [guid]::NewGuid().ToString('N')) $file = Join-Path $directory 'Instalar-P2PScreenShare-Online.exe' $tls = [Net.ServicePointManager]::SecurityProtocol try { [Net.ServicePointManager]::SecurityProtocol = $tls -bor [Net.SecurityProtocolType]::Tls12 $null = New-Item -ItemType Directory -Path $directory Write-Host 'Baixando e conferindo o instalador P2PScreenShare...' Invoke-WebRequest -UseBasicParsing -Uri $download -OutFile $file -TimeoutSec 120 -MaximumRedirection 5 if ((Get-Item -LiteralPath $file).Length -gt 10000000 -or (Get-FileHash -LiteralPath $file -Algorithm SHA256).Hash -ne $hash) { throw 'Download recusado. O arquivo nao corresponde ao instalador esperado. Confira o link, o acesso publico e se o Drive exibiu uma pagina de confirmacao. Nada foi executado.' } Set-Content -LiteralPath $file -Stream Zone.Identifier -Value (@('[ZoneTransfer]', 'ZoneId=3') -join [Environment]::NewLine) Write-Host 'Arquivo verificado. Abrindo a janela de instalacao...' $process = Start-Process -FilePath $file -Wait -PassThru if ($process.ExitCode -ne 0) { throw ('O instalador encerrou com codigo ' + $process.ExitCode + '. Consulte a mensagem do Windows ou o registro da instalacao.') } } finally { [Net.ServicePointManager]::SecurityProtocol = $tls if (Test-Path -LiteralPath $file) { Remove-Item -LiteralPath $file -Force } if (Test-Path -LiteralPath $directory) { Remove-Item -LiteralPath $directory } } }