asheroto / winget-install

Install winget tool using PowerShell! Prerequisites automatically installed. Works on Windows 10/11 and Server 2019/2022.
https://bit.ly/winget-install
GNU General Public License v3.0
272 stars 33 forks source link

[Request]: Fall back to a different download/install method if current method fails #45

Closed vavavr00m closed 3 months ago

vavavr00m commented 3 months ago

Describe the feature or improvement you're requesting

Freshly installed W11 23h2 and fully updated. It had winget installed at first but somehow it got messed up and just refuses to be reinstalled. Tried your script but it just terminates and checking the winget command after still says winget is not a recognized command. What worked for me was manually downloading the .msixbundle from the official repo, launched it and clicked reinstall, manually add the path environment variable: %UserProfile%\AppData\Local\Microsoft\WindowsApps. Maybe add that to the script?

Additional context

Can't file a bug report now since I didn't know there was troubleshooting guide until a Feature Request was initiated. Just to add, this script was also downloaded manually and ran locally and got the same result.

asheroto commented 3 months ago

Gotcha. I will try installing fresh Windows 11 23H2 to try to replicate the result in a virtual machine.

The window terminating is annoying! It's on the to do list to fix, for now you can do -wait.

If you were able to get it installed manually then I should be able to fix the script to make it work.

Thanks for the heads-up, will check later tonight or tomorrow.

vavavr00m commented 3 months ago

Thanks. Will try -wait next time.

To be honest, I don't know what caused it because I tried a bunch of scripts. I was looking for a script that installs all available package managers & their dependencies and then add to path environment variable plus download, build/install some other stuff especially those needing to be added to path env. variable but couldn't find one script that supports all and was researching about how to make a script like that. Here's what I found so far, some of which was tried, and must've messed things up:

My best guess is this one because it triggered an issue for me - blank boot screen - but to be fair, the PC was already having BSOD prior, thus, the issues could be unrelated. Second guess is your own winget-install script - I was under the impression that running the below will just upgrade winget to the latest or not touch it if it is already up-to-date:

&([ScriptBlock]::Create((irm https://raw.githubusercontent.com/asheroto/winget-install/master/winget-install.ps1))) -Force

Third is winutil but it was already not working when I tried installing winget from there iirc. The commands used were:

irm "https://raw.githubusercontent.com/ChrisTitusTech/winutil/main/winutil.ps1" | iex
irm christitus.com/win | iex
iwr -useb https://christitus.com/win | iex

If it doesn't mess up your environment variables then one of the things at the top of the post could have. If not, I'm out of ideas.

Anyway, I can't read PowerShell just yet but I can see from the descriptions that winget-install checks if winget is installed and checks if it was added to path but I do not know if the script:

  1. checks if winget is already installed in the following location(s):
    • %LOCALAPPDATA%\Microsoft\WindowsApps - source
  2. ensures user/system environment variable has the correct path as the installed winget if that is even possible.

In my case, winget came w/ Windows 11 afaik and is already installed in %UserProfile%\AppData\Local\Microsoft\WindowsApps but the environment variable was missing, therefore, causing Get-Command -Name winget to fail.

asheroto commented 3 months ago

FYI, ChrisTitusTech just uses this script. 😊

I downloaded the ISO from here on 2024-06-25: https://www.microsoft.com/en-us/software-download/windows11

Checksum sha256 is 36de5ecb7a0daa58dce68c03b9465a543ed0f5498aa8ae60ab45fb7c8c4ae402. Version 23H2 (OS Build 22631.2861).

Installed in a VM using Hyper-V.

winget is already included in later versions of Windows 11, so no need to install it on that. Fresh install, winget command works immediately after installing Windows.

image

Then I ran this command...

&([ScriptBlock]::Create((irm asheroto.com/winget))) -Force -Wait

I found that winget.exe still works after running.

If you have a different ISO version, please let me know the sha256 checksum and I can try and find that version to download. It may be an older version.

vavavr00m commented 3 months ago

Thanks for letting me know that ChrisTitusTech is using this script.

Here are the details: winver: image sha256 checksum (using Jacksum 3.7.0 Hashgarten 0.17.0 for Windows 2.8.0): 189a8818b179b5c97e1c0c8223c79eba69a5d9c249292efe90b43e94c5f13c44 iso: image downloaded and made into an ISO by MediaCreationTool and installed via Ventoy 1.0.98 on a USB flash drive image

As mentioned previously, some script messed w/ the path environment variable and removed %LOCALAPPDATA%\Microsoft\WindowsApps. To replicate the issue, I don't think you have to use the exact ISO, just remove the environment variable for winget (mine is %LOCALAPPDATA%\Microsoft\WindowsApps) and run winget-install. Here's the output w/ the -wait flag added:

image

asheroto commented 3 months ago

Gotcha, thanks for the info!

I created an ISO using the Media Creation Tool just now and installed Windows in a VM.

winget still works. Running the script with the command I used before also works...

image

Maybe it's another script that's causing the issue?

Looks like when winget is installed it adds its own path to the user's PATH variable: image

That's okay though, I could see where this might occur for some oddball reason, even if we can't find that reason right now. I went ahead and added the ability to check the PATH variable and add it in if it doesn't exist.

Run this for me and tell me if it works now:

$url = "https://raw.githubusercontent.com/asheroto/winget-install/4ac35195876d9b1206283ae572024159b189a793/winget-install.ps1"
&([ScriptBlock]::Create((irm $url))) -Force -NoExit -Debug

Also added the -NoExit param to version 4.2.0.

asheroto commented 3 months ago

Oops, fixed the URL, try the updated one.

vavavr00m commented 3 months ago

Didn't work for me.

PS C:\Windows\system32> winget
winget : The term 'winget' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ winget
+ ~~~~~~
    + CategoryInfo          : ObjectNotFound: (winget:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

PS C:\Windows\system32> $url = "https://raw.githubusercontent.com/asheroto/winget-install/4ac35195876d9b1206283ae572024159b189a793/winget-install.ps1"
>> &([ScriptBlock]::Create((irm $url))) -Force -NoExit -Debug
winget-install 4.2.0
To check for updates, run winget-install -CheckForUpdate
To delay script exit, run winget-install -Wait
To force script pausing after execution, run winget-install -NoExit

#################
# Prerequisites #
#################

Downloading VCLibs...
DEBUG: Downloading VCLibs from https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx to
%LOCALAPPDATA%\Temp\wxi2vh5d.zvg

Downloading UI.Xaml...
DEBUG: Downloading UI.Xaml from
https://github.com/microsoft/microsoft-ui-xaml/releases/download/v2.8.6/Microsoft.UI.Xaml.2.8.x64.appx to
%LOCALAPPDATA%\Temp\3nkatuvc.l0i

##########
# winget #
##########

DEBUG: Getting latest release...
Downloading winget license...
DEBUG: Downloading winget license from
https://github.com/microsoft/winget-cli/releases/download/v1.8.1762/fc2c4f481bae4326b6104907449dad99_License1.xml to
%LOCALAPPDATA%\Temp\oy3op02d.4rz

Downloading winget...
DEBUG: Downloading winget from https://aka.ms/getwinget to %LOCALAPPDATA%\Temp\ojnmmhqq.v00

Installing winget and its dependencies...

###################################################
# WARNING! An error occurred during installation! #
###################################################

WARNING: If messages above don't help and the problem persists, please read the Troubleshooting section
of the README: https://github.com/asheroto/winget-install#troubleshooting
WARNING: Make sure you have the latest version of the script by running this command: winget-install -CheckForUpdate

WARNING: Error: Add-AppxProvisionedPackage failed. Error code = 0xc1570118
Script completed. Pausing indefinitely. Press any key to exit...
asheroto commented 3 months ago

Hmm. I don't understand why it works for me and not you. When using the media creation tool, you select Make ISO, 23H2, right?

What language and locale / keyboard? Maybe that's why.

vavavr00m commented 3 months ago

Yes I chose Auto ISO and 23H2 (last option). Keyboard should be the standard US QWERTY keyboard.

image

asheroto commented 3 months ago

Hmm, that's the same as me.

After installing, is that the first script you run? Seems like something is interfering here.

vavavr00m commented 3 months ago

No idea what was the first script I ran but if I were to guess, one of the first scripts was iwr -useb https://raw.githack.com/harryeffinpotter/PC-Gaming-Redists-AIO/master/Install.ps1 | iex. First thing I did though was install Chrome from the official page and run . Pitch Black Theme.reg downloaded from this gist

What about script execution policy? I've read something about bypassing that for the specific script but IDK how to go about it.

asheroto commented 3 months ago

What's really odd is that since winget is included in Windows 11, the path should absolutely be in the environment variables. So it's almost like they were removed. At first you said it installed but just didn't run. So I'm guessing other scripts modified or interfered with winget.

Since I'm using the same exact image but it works fine, the issue must be caused by some outside script. Not sure if something else corrupted Windows or what's going on.

I did add the ability to confirm the environment path. Apart from that, not much else changed in the script. So this should be good. I'll run a few more tests and then release this update.

Thanks for the heads-up!