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

Install as SYSTEM user #19

Closed adamsewell closed 7 months ago

adamsewell commented 1 year ago

It seems there might be a limitation of using this script as the SYSTEM account. I don't know if this is a limitation of winget itself or the installer. If it's winget, you might consider to put a check in the install to check if it's being ran as SYSTEM. If not, could it be added?

asheroto commented 1 year ago

Hi, what's the advantage of installing as system? If you install manually, it doesn't install as system, does it?

adamsewell commented 1 year ago

Apologies, I forgot to respond. The advantage of installing as SYSTEM would be in use cases of RMM's or remote management in general, The ability to install winget on the system without user interaction is extremely helpful. Unless I'm missing something, and it's possible.

asheroto commented 1 year ago

It's okay.

Running this script installs without user interaction. What's the advantage of installing as SYSTEM? I'm pretty sure it installs for all users. 😊

adamsewell commented 1 year ago

Right but my RMM runs scripts as SYSTEM, I can’t install it as is because of this. If that makes sense.

Thanks, -Adam

MyGeek Technologies ..**** https://mygeeknc.com

From: asheroto @.> Sent: Wednesday, September 13, 2023 9:28 PM To: asheroto/winget-install @.> Cc: Adam Sewell @.>; Author @.> Subject: Re: [asheroto/winget-install] Install as SYSTEM user (Issue #19)

It's okay. Running this script installs without user interaction. What's the advantage of installing as SYSTEM? I'm pretty sure it installs for all users. 😊 β€” Reply to this email directly, view it on Caution: External @.**@.>) Graymail Detailshttps://protection.inkyphishfence.com/details?id=bXlnZWVrLXRlY2hub2xvZ2llcy9hZGFtLnNld2VsbEBteWdlZWtuYy5jb20vM2I4MWJhN2U1Y2RlODRhYTk3MjRlNzkwM2Y3YTliMGQvMTY5NDY1NDkwMS4yMw==#key=33fda6c08b47adf554dd6794b73f81e4 Report This Emailhttps://protection.inkyphishfence.com/report?id=bXlnZWVrLXRlY2hub2xvZ2llcy9hZGFtLnNld2VsbEBteWdlZWtuYy5jb20vM2I4MWJhN2U1Y2RlODRhYTk3MjRlNzkwM2Y3YTliMGQvMTY5NDY1NDkwMS4yMw==#key=33fda6c08b47adf554dd6794b73f81e4 FAQhttps://www.inky.com/banner-faq

It's okay.

Running this script installs without user interaction. What's the advantage of installing as SYSTEM? I'm pretty sure it installs for all users. 😊

β€” Reply to this email directly, view it on GitHubhttps://shared.outlook.inky.com/link?domain=github.com&t=h.eJxVj8EOgjAMhl_FzKswBoMxTrxKGRUWxmZYCTHGd9fpwXhr2q_9-j_YvjnWndhMdIsd55OleR9yE1YOccYtUOCH9RNSZn0kcI7bGHeMXOjzp3qjK3rKhBJtXcui0uxyYks6ut4nxCUjNLMPLkz2vQYjrHnEA53rv3NvPrpqaMUACmszYisBtColKl1UVwV6KEYuGi2bWupC5GWVHJgcPpC9WgNkg4_97_0EjAn4b1FKK54vgypP4A.MEUCIHYR17yyElosThXBNCOSEid_XOxZXGlkKhH5Ko4BO_8nAiEAoJx6ZAgrLgKuEbYb1AqWWUvb0iGhcmHZcB-H0YKe_Vg, or unsubscribehttps://shared.outlook.inky.com/link?domain=github.com&t=h.eJxVkMFuwjAQRH8F-VziJHYczIm0CBAUVGiQ2t5sZ0ksEhthW1VV9d8r00PFHHdGerPzjcK1R9MR6ry_uCnGrfZdkImyAzbW65NWwmtrHA7GBenUVUsYi-A7XFVLtt_X9eG4qFcFeT8snwk5zt_y9bZ-rHZPu8XrllU30c3LB5tT9DBC5wgbvlqA89iD6oztbavBYdGIIXHwCX0_-_ONutUgcpJJUUKhGphQIXiZUyh5Sk6l4DJtcMY4ZQXlaZbkJDIgMu7az_7fioEmBu5PPq6Q_fwCW4xV4g.MEUCIQDfM2cQxlhg5E37yiXHkBEywb04YjJy6nO8rg8VNvZzBAIgSkz1fHvqX0f04UDQJ2LmeEugS99Nryz3oUERK2rBzFY. You are receiving this because you authored the thread.Message ID: @.**@.>>

asheroto commented 1 year ago

Can you have your RMM run the install script?

I'm not sure how it could be installed as SYSTEM, but if you look through the script and find the command to do so I will implement the option as parameter.

It doesn't install like a service or regular program does.

myrandor commented 9 months ago

I'd love to have to option too in order to deploy using an RMM, and install packages for all users.

I was able to use the SYSTEM user before. But I had to stop using Add-AppxPackage, and use DISM.

Example dism /Online /Add-ProvisionedAppxPackage /PackagePath:"$Path\$File.appx" /SkipLicense

asheroto commented 9 months ago

Just curious, what RMM are you using that installs as system?

I see what you mean now.

Can you not install it running as the administrator account? or with something like runas.exe?

If not I could add this in I think, reopening.

https://superuser.com/questions/647927/install-windows-store-app-package-appx-for-all-users#983475 https://stackoverflow.com/questions/70265755/windows-10-oobe-post-setup-how-to-allow-powershell-add-appxpackage https://techcommunity.microsoft.com/t5/windows-powershell/run-add-apppackage-using-user-system/m-p/2267824

asheroto commented 9 months ago

So in doing some research it appears that this command

dism.exe /Online /Add-ProvisionedAppxPackage /PackagePath:"$packagePath" /SkipLicense 

is the same as this command

Add-AppxProvisionedPackage -Online -PackagePath "$packagePath" -SkipLicense

since it is part of the dism module.

According to this page it says it will be installed for the current user and new users, but not "all users". Have you found this to be the case on your end?

asheroto commented 9 months ago

Also, rather than it installing as SYSTEM it actually just installed as a provisioned package that is installed when new users sign up.

Will that still satisfy your requirements?

Was going to implement it with a new -AllUsers parameter.

asheroto commented 9 months ago

See if this works for you: https://github.com/asheroto/winget-install/blob/Add-System-Install/winget-install.ps1

Use like this:

./winget-install.ps1 -AllUsers -Force
myrandor commented 8 months ago

Just curious, what RMM are you using that installs as system?

For me, I'm using NinjaOne. From the interface, I can access system shell and system powershell directly. And since some computer have multiple users on it, I want to deploy app "Globally".

Can you not install it running as the administrator account? or with something like runas.exe?

I can run any scripts as any users with NinjaOne, it's just that NinjaOne uses system as the default account. For any installation/management, it does the job!

Shaun-Silli commented 8 months ago

I haven't looked into this much, but the reason I was trying to run it as 'system' is for Microsoft Intune I want to set Winget up as a dependency for all apps packaged via Winget to avoid any issue with people trying to install apps from company portal and Winget isn't install on their login profile, the app will just fail. having Winget as a dependency if it is missing it will run the script first install Winget then deploy whatever app they trying to install from company portal.

Microsoft Intune does allow things to run as the user, but most of my users aren't local admins on their computers, and I don't want them seeing any popup windows. -

but besides that, it's an excellent script and very helpful - thanks!

Shaun-Silli commented 8 months ago

See if this works for you: https://github.com/asheroto/winget-install/blob/Add-System-Install/winget-install.ps1

Use like this:

./winget-install.ps1 -AllUsers -Force

Didn't see your comment from earlier - just gave the -AllUsers a shot and it works well, script run under the 'system' account and ran all the with to the end, I did get one error/warning at the end when it tried registering winget... or detecting it install?



#########################
# Registering winget... #
#########################

Add-AppxPackage : Deployment failed with HRESULT: 0x80073CF9, Install failed. Please contact your software vendor. (Exception from HRESULT: 0x80073CF9)
Deployment Register operation rejected on package Microsoft.DesktopAppInstaller_2023.1215.611.0_neutral_~_8wekyb3d8bbwe from: AppxBundleManifest.xml install request because the Local System account is not allowed to perform this
operation.
NOTE: For additional information, look for [ActivityId] cdfb4fa7-4b43-0000-195e-06ce434bda01 in the Event Log or use the command line Get-AppPackageLog -ActivityID cdfb4fa7-4b43-0000-195e-06ce434bda01
At C:\Users\******\Test-WinGet-Install.ps1:1281 char:9
+         Add-AppxPackage -RegisterByFamilyName -MainPackage Microsoft. ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (Microsoft.Deskt...r_8wekyb3d8bbwe:String) [Add-AppxPackage], IOException
    + FullyQualifiedErrorId : DeploymentError,Microsoft.Windows.Appx.PackageManager.Commands.AddAppxPackageCommand

winget command registered successfully.

##########################
# Installation complete! #
##########################

Checking if winget is installed and working...
WARNING: winget is installed but is not detected as a command. Try using winget now. If it doesn't work, wait about 1 minute and try again (it is sometimes delayed). Also try restarting your computer.
WARNING: If you restart your computer and the command still isn't recognized, 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

Thanks

asheroto commented 8 months ago

Gotcha.

I'm working on a totally revised edition of the script #36.

Try this

&([ScriptBlock]::Create((irm https://raw.githubusercontent.com/asheroto/winget-install/v4/winget-install.ps1))) -Force -Wait
Shaun-Silli commented 8 months ago

Yeah gave that a shot but the parameter for allusers is missing from V4 so couldn't run as system to test it out for my use-case.

did run it on my login to help with the testing of v4 just to help out where I can, I got a similar error others have reported for V4 booms out almost immediately. - let me know if need it tested on a clean build happy to try it on that as well.


.\Winget-Deployment.ps1 -Force -Wait
winget-install 4.0.0
To check for updates, run winget-install -CheckForUpdate

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

Installing x64 VCLibs...

###################################################
# 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: Element not found.

Waiting for 10 seconds before exiting...
asheroto commented 8 months ago

Hmm.. so do you need this to actually run as SYSTEM or just install to all user accounts?

This doesn't run as SYSTEM but rather installs to all users. I guess I misunderstood.

The command you mentioned here should install to all users, which is effectively what the script does.

It's difficult for me to troubleshoot since it works on my end, but maybe you could run them each? There's only a few.

Download this: https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx

Then run this:

Add-AppxProvisionedPackage -Online -PackagePath "$packagePath" -SkipLicense

Where $packagePath is the path to the appx file.

asheroto commented 8 months ago

Just curious, does this work? It's Microsoft's newer instructions...

$progressPreference = 'silentlyContinue'
Write-Information "Downloading WinGet and its dependencies..."
Invoke-WebRequest -Uri https://aka.ms/getwinget -OutFile Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle
Invoke-WebRequest -Uri https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx -OutFile Microsoft.VCLibs.x64.14.00.Desktop.appx
Invoke-WebRequest -Uri https://github.com/microsoft/microsoft-ui-xaml/releases/download/v2.7.3/Microsoft.UI.Xaml.2.7.x64.appx -OutFile Microsoft.UI.Xaml.2.7.x64.appx
Add-AppxPackage Microsoft.VCLibs.x64.14.00.Desktop.appx
Add-AppxPackage Microsoft.UI.Xaml.2.7.x64.appx
Add-AppxPackage Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle
asheroto commented 8 months ago

I revised the v4 script. Let me know if this works for you now.

&([ScriptBlock]::Create((irm https://raw.githubusercontent.com/asheroto/winget-install/v4/winget-install.ps1))) -Force -Wait
moorsey commented 7 months ago

Hey, I just grabbed the latest V4.0.1 but the allusers parameter doesn't seem to be in the code, although is mentioned in the release notes at the top of the script.

Running winget-install.ps1 -allusers -force

Gives me:

A parameter cannot be found that matches parameter name 'allusers'.

Thanks!

asheroto commented 7 months ago

@moorsey generally for a new question you would need to create a new issue.

The reason AllUsers doesn't work is because the new script as of version 4 installs to all users by default.