Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REQUEST] Wiki Page for Supplied "extras"? #108

Open
Hammerfest opened this issue Nov 12, 2024 · 4 comments
Open

[REQUEST] Wiki Page for Supplied "extras"? #108

Hammerfest opened this issue Nov 12, 2024 · 4 comments

Comments

@Hammerfest
Copy link

There have been a few issue tickets where I have seen links to prefilled out commands for first login or other non-generator actions.
Sadly, without searching through closed issues, its hard to find these.

Please consider opening the Wiki section up for this or perhaps a pinned issue thread with links/brief description for all, just something to prevent digging and duplicate tickets.

@cschneegans
Copy link
Owner

I have now added a page to collect sample scripts. Some of those scripts are from closed issues, others are from my “private” archives.

@cschneegans
Copy link
Owner

I have added a sample script to Use the WinGet package manager to install Firefox – which was way more complicated than expected.

I had not used WinGet before and have realized just now what a mess it still is. Even with Windows 11 24H2, you cannot simply run winget.exe in a “FirstLogon” script. Instead, you have to wait a minute or two until that link in the admin's profile directory (%LOCALAPPDATA%\Microsoft\WindowsApps\winget.exe of type IO_REPARSE_TAG_APPEXECLINK) appears.

If anyone has experience with WinGet on Windows 10 or Windows 11 releases prior to 24H2, what is the recommended way to set up WinGet silently?

@dcoffin88
Copy link

dcoffin88 commented Dec 29, 2024

@cschneegans

I was only having issues with Winget prior to Windows 11 but you could modify my Winget install/update script by removing the user input check, then it will run silently.

# Function to restart the script with elevation if needed
    function Ensure-Admin {
        if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
            Write-Host "Script is not running with elevated privileges. Restarting as Administrator..."
            Start-Process powershell.exe -ArgumentList "-NoProfile", "-ExecutionPolicy Bypass", "-File", "`"$PSCommandPath`"" -Verb RunAs
            exit
        }
    }

# Ensure script is running with admin privileges
Ensure-Admin

$userInput = Read-Host "Do you want to install/update Winget (Y/N): "

if ($userInput -eq 'Y') {
    # Define log file path
    $logFilePath = "C:\Windows\Setup\Scripts\InstallUpdateWinget.log"

    # Function to log messages
    function Log-Message {
        param(
            [string]$message
        )
        $timestamp = (Get-Date).ToString("yyyy-MM-dd HH:mm:ss")
        "$timestamp - $message" | Out-File -Append -FilePath $logFilePath
    }

    # Start logging
    Log-Message "Script started."

    # Define the download path
    $downloadPath = "C:\Windows\Setup\Scripts"

    # Check if the directory exists, if not, create it
    if (-not (Test-Path -Path $downloadPath)) {
        New-Item -Path $downloadPath -ItemType Directory
        Log-Message "Created download path directory: $downloadPath"
    }

    # Check system architecture (64-bit or 32-bit)
    $is64Bit = [System.Environment]::Is64BitOperatingSystem
    if ($is64Bit) {
        $architecture = "64-bit"
    } else {
        $architecture = "32-bit"
    }
    Log-Message "System architecture: $architecture"

    # Select download URLs based on system architecture
    if ($is64Bit) {
        $vcRedistUrl = "https://aka.ms/vs/17/release/VC_redist.x64.exe"
        $wingetUrl = "https://aka.ms/getwinget"
        $vclibsUrl = "https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx"
        $uixamlUrl = "https://github.com/microsoft/microsoft-ui-xaml/releases/download/v2.8.6/Microsoft.UI.Xaml.2.8.x64.appx"
        Log-Message "Downloading 64-bit packages."
    } else {
        $vcRedistUrl = "https://aka.ms/vs/17/release/VC_redist.x86.exe"
        $wingetUrl = "https://aka.ms/getwinget"
        $vclibsUrl = "https://aka.ms/Microsoft.VCLibs.x86.14.00.Desktop.appx"
        $uixamlUrl = "https://github.com/microsoft/microsoft-ui-xaml/releases/download/v2.8.6/Microsoft.UI.Xaml.2.8.x86.appx"
        Log-Message "Downloading 32-bit packages."
    }

    # Download WinGet & dependencies to C:\Windows\Setup\Scripts
    Log-Message "Downloading dependencies..."
    Invoke-WebRequest -Uri $vcRedistUrl -OutFile "$downloadPath\VC_redist.exe" -Verbose
    Invoke-WebRequest -Uri $wingetUrl -OutFile "$downloadPath\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" -Verbose
    Invoke-WebRequest -Uri $vclibsUrl -OutFile "$downloadPath\Microsoft.VCLibs.appx" -Verbose
    Invoke-WebRequest -Uri $uixamlUrl -OutFile "$downloadPath\Microsoft.UI.Xaml.appx" -Verbose
    Log-Message "Dependencies downloaded successfully."

    # Proceed with installing WinGet and dependencies
    Log-Message "Installing dependencies..."
    Start-Process -FilePath "$downloadPath\VC_redist.exe" -Args "/quiet /norestart" -Wait
    Add-AppxProvisionedPackage -Online -Packagepath "$downloadPath\Microsoft.VCLibs.appx" -SkipLicense | Out-Null
    Add-AppxProvisionedPackage -Online -Packagepath "$downloadPath\Microsoft.UI.Xaml.appx" -SkipLicense | Out-Null

    try {
        # Install Microsoft.DesktopAppInstaller MSIX package
        Add-AppxProvisionedPackage -Online -Packagepath "$downloadPath\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" -SkipLicense | Out-Null
        Log-Message "Microsoft.DesktopAppInstaller installed successfully."
    } catch {
        Log-Message "Error installing Microsoft.DesktopAppInstaller: $_"
    }

    Log-Message "Installation of dependencies complete."

    # Verify install status
    $wingetPath = @(Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_*64__8wekyb3d8bbwe")
    if ($wingetPath) {
        set-location -path $wingetPath[-1]
        $microsoftDesktopAppInstallerVer = (Get-AppxProvisionedPackage -Online | Where-Object {$_.DisplayName -eq "Microsoft.DesktopAppInstaller"}).Version
        .\winget.exe -v | Out-String -OutVariable windowsPackageManagerVer | Out-Null
        Log-Message "`nWinGet installation complete."
        Log-Message "Detected Microsoft.DesktopAppInstaller version: $($microsoftDesktopAppInstallerVer)"
        Log-Message "Detected Windows Package Manager version: $($windowsPackageManagerVer.trim())"
    } else {
        Log-Message "Winget installation failed."
    }

    # End logging
    Log-Message "Script finished."
} else {
    Write-Host "Winget installation and upgrade was skipped."
}

@ProgrammerBruce
Copy link

I have added a sample script to Use the WinGet package manager to install Firefox – which was way more complicated than expected.

I had not used WinGet before and have realized just now what a mess it still is. Even with Windows 11 24H2, you cannot simply run winget.exe in a “FirstLogon” script. Instead, you have to wait a minute or two until that link in the admin's profile directory (%LOCALAPPDATA%\Microsoft\WindowsApps\winget.exe of type IO_REPARSE_TAG_APPEXECLINK) appears.

If anyone has experience with WinGet on Windows 10 or Windows 11 releases prior to 24H2, what is the recommended way to set up WinGet silently?

This response by @cschneegans is an example of why the request for a wiki was made. Please enable the wiki and the discussions for this repo.

https://docs.github.com/en/communities/documenting-your-project-with-wikis/about-wikis

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants