@cls
@echo off
>nul chcp 437
title Chrome Download Tool

:: Some Credit
:: AveYo For Export Function, ReadAllText Function
:: kaljukass for set_chrome_as_default_browser Registry trick
:: Google for helpfull endless information

:::: Run as administrator, AveYo: ps\vbs version
1>nul 2>nul fltmc || (
    set "_=call "%~dpfx0" %*" & powershell -nop -c start cmd -args '/d/x/r',$env:_ -verb runas || (
    >"%temp%\Elevate.vbs" echo CreateObject^("Shell.Application"^).ShellExecute "%~dpfx0", "%*" , "", "runas", 1
    >nul "%temp%\Elevate.vbs" & del /q "%temp%\Elevate.vbs" )
    exit)

call :export set_chrome_as_default_browser > "%temp%\set_chrome_as_default_browser.reg"
call :GetLatestChrome
goto :eof

:GetLatestChrome:
set ^ #=& set "0=%~f0"& set 1=%*& powershell -nop -c iex(([io.file]::ReadAllText($env:0)-split':GetLatestChrome\:.*')[1])& exit /b
function GetLatestChrome ($cmd) {
    
    $set_chrome_as_default_browser=$env:temp+'\set_chrome_as_default_browser.reg'
    $Proc = Get-WMIObject -Classname Win32_Process | Where-Object Name -Match 'chrome.exe'
    $Prod = Get-WMIObject -Classname Win32_Product | Where-Object Name -Match 'Google Chrome'
    
    <# https://stackoverflow.com/questions/31977657/determining-32-64-bit-in-powershell #>
    if ((gwmi win32_operatingsystem | select osarchitecture).osarchitecture -eq "64-bit")
    {
        $ChromeTempFile=$env:temp+'\googlechromestandaloneenterprise64.msi'
        $ChromeDownloadURL='https://dl.google.com/chrome/install/googlechromestandaloneenterprise64.msi'
    }
    else
    {
        $ChromeTempFile=$env:temp+'\googlechromestandaloneenterprise.msi'
        $ChromeDownloadURL='https://dl.google.com/chrome/install/googlechromestandaloneenterprise.msi'
    }

    try {
        Write-Host
        Write-Host '  ### Download latest Chrome'
        (new-object Net.WebClient).DownloadFile($ChromeDownloadURL, $ChromeTempFile)
    }
    catch {
        Write-Host
        Write-Host '  ### [ ERROR ] Check your internet connection'
        Write-Host
        Write-Host '  Script will end in 3 Seconds'
        Start-Sleep -s 3
        [Environment]::Exit(1)
    }
    
    Write-Host '  ### Close Chrome'
    if ($Proc) {Stop-Process -Name "Chrome" -Force}

    Write-Host '  ### Remove old version'
    if ($Prod) {$Prod.UnInstall() | Out-Null}
    
    Write-Host '  ### Install new version'
    start $ChromeTempFile -args '/qn' -Wait
    
    Write-Host '  ### Remove Temporary files'
    Remove-Item $ChromeTempFile
    
    try {
        Write-Host '  ### Start Chrome'
        start Chrome
    }
    catch {
        Write-Host
        Write-Host '  ### [ ERROR ] Chrome Installtion failed'
        Write-Host
        Write-Host '  Script will end in 3 Seconds'
        Start-Sleep -s 3
        [Environment]::Exit(1)
    }
    
    Write-Host '  ### Settings Chrome As Default Browser (thanks to kaljukass)'
    start reg -args 'import ',$set_chrome_as_default_browser
    
    Write-Host
    Write-Host '  Script will end in 2 Seconds'
    Start-Sleep -s 3
    [Environment]::Exit(1)
    
}; <#,#>  GetLatestChrome $env:1;  #:GetLatestChrome:

:export
rem AveYo's :export text attachments snippet
setlocal enabledelayedexpansion || Prints all text between lines starting with :NAME:[ and :NAME:] - A pure batch snippet by AveYo
set [=&for /f "delims=:" %%s in ('findstr/nbrc:":%~1:\[" /c:":%~1:\]" "%~f0"') do if defined [ (set/a ]=%%s-3) else set/a [=%%s-1
<"%~fs0" ((for /l %%i in (0 1 %[%) do set /p =)&for /l %%i in (%[% 1 %]%) do (set txt=&set /p txt=&echo(!txt!)) &endlocal &exit/b

:set_chrome_as_default_browser:[
Windows Registry Editor Version 5.00

;; Change the default Web Browser is now difficult...??
;; https://forums.mydigitallife.net/threads/change-the-default-web-browser-is-now-difficult.84247/#post-1695228

[HKEY_CLASSES_ROOT\http]
@="URL:http"
"AppUserModelID"="Microsoft.InternetExplorer.Default"
"EditFlags"=dword:00000002
"FriendlyTypeName"="@C:\\Windows\\system32\\ieframe.dll,-903"
"Source Filter"="{E436EBB6-524F-11CE-9F53-0020AF0BA770}"
"URL Protocol"=""

[HKEY_CLASSES_ROOT\http\DefaultIcon]
@="C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe,0"

[HKEY_CLASSES_ROOT\http\Extensions]
".ASF"="{187463A0-5BB7-11D3-ACBE-0080C75E246E}"
".WM"="{187463A0-5BB7-11D3-ACBE-0080C75E246E}"
".WMA"="{187463A0-5BB7-11D3-ACBE-0080C75E246E}"
".WMV"="{187463A0-5BB7-11D3-ACBE-0080C75E246E}"

[HKEY_CLASSES_ROOT\http\shell]
@="open"

[HKEY_CLASSES_ROOT\http\shell\open]
"CommandId"="IE.Protocol"
"DontReturnProcessHandle"=""

[HKEY_CLASSES_ROOT\http\shell\open\command]
@="\"C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe\" -- \"%1\""
"DelegateExecute"="{17FE9752-0B5A-4665-84CD-569794602F5C}"

[HKEY_CLASSES_ROOT\https]
@="URL:https"
"AppUserModelID"="Microsoft.InternetExplorer.Default"
"EditFlags"=dword:00000002
"FriendlyTypeName"="@C:\\Windows\\system32\\ieframe.dll,-904"
"Source Filter"="{E436EBB6-524F-11CE-9F53-0020AF0BA770}"
"URL Protocol"=""

[HKEY_CLASSES_ROOT\https\DefaultIcon]
@="C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe,0"

[HKEY_CLASSES_ROOT\https\shell]
@="open"

[HKEY_CLASSES_ROOT\https\shell\open]
"CommandId"="IE.Protocol"

[HKEY_CLASSES_ROOT\https\shell\open\command]
@="\"C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe\" -- \"%1\""
"DelegateExecute"="{17FE9752-0B5A-4665-84CD-569794602F5C}"
:set_chrome_as_default_browser:]

文章標籤
全站熱搜
創作者介紹
創作者 台南面交服務 的頭像
台南面交服務

電腦台南面交服務

台南面交服務 發表在 痞客邦 留言(0) 人氣(3)