asktechsupport / help

help@asktechsupport
5 stars 0 forks source link

Progress bar to install AV isn't visually indicating anything... #68

Closed asktechsupport closed 3 months ago

asktechsupport commented 3 months ago

At the moment, the visual progress bar I get is a bit naf, I don't know whether its the colour of the progress bar matching the blue..?

image

asktechsupport commented 3 months ago

Resolved

Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
# Define the URL for the latest Chrome installer
$chromeInstallerUrl = "https://www.google.com/chrome/next-steps.html?statcb=0&installdataindex=empty&defaultbrowser=0#"

# Define the local path where the installer will be saved
$installerPath = "$env:TEMP\chrome_installer.exe"

# Function to download a file with a progress bar
function Download-FileWithProgress {
    param (
        [string]$url,
        [string]$destination
    )

    # Create a web client
    $webClient = New-Object System.Net.WebClient

    # Set up an event handler to update the progress bar
    $webClient.DownloadProgressChanged += {
        param($sender, $e)

        # Calculate percent complete and display progress bar
        $percentComplete = $e.ProgressPercentage
        Write-Progress -Activity "Downloading Chrome" -Status "$percentComplete% Complete" -PercentComplete $percentComplete
    }

    # Download the file
    $webClient.DownloadFile($url, $destination)
}

# Download the Chrome installer
Download-FileWithProgress -url $chromeInstallerUrl -destination $installerPath

# Simulate installation process with a progress bar
$totalSteps = 100
for ($i = 1; $i -le $totalSteps; $i++) {
    # Update the progress bar
    $percentComplete = ($i / $totalSteps) * 100
    Write-Progress -Activity "Installing Chrome" -Status "Progress: $percentComplete% Complete" -PercentComplete $percentComplete

    # Simulate some work with Start-Sleep
    Start-Sleep -Milliseconds 30
}

# Install Chrome silently
Write-Host "Starting Chrome installation..."
Start-Process -FilePath $installerPath -ArgumentList "/silent /install" -NoNewWindow -Wait

# Indicate that the installation is complete
Write-Host "Chrome installation completed successfully!"

# Clean up the installer
Remove-Item -Path $installerPath -Force