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

System Context #3049

Open
cgerke opened this issue Mar 6, 2023 · 12 comments
Open

System Context #3049

cgerke opened this issue Mar 6, 2023 · 12 comments
Labels
Context-System Related to system context (nt authority/session 0) Issue-Docs It's a documentation issue that really should be on MicrosoftDocs Issue-Feature This is a feature request for the Windows Package Manager client. Needs-Author-Feedback Issue needs attention from issue or PR author PowerShell Issue related to WinGet PowerShell Module or cmdlet

Comments

@cgerke
Copy link

cgerke commented Mar 6, 2023

Description of the new feature / enhancement

This really shouldn't be moved to a discussion.

Not having the option to run winget in the System Context will essentially stop most organisations using winget. Zero Trust is a framework that more and more organisations will be adopting. Local admin rights is a dinosaur.

Some interesting stats with the winget-pkgs manifests, doing a search of InstallerType across the git repo show that msix is really a small component of what people are installing with the winget tool.

11940 results in 11134 files InstallerType: nullsoft (exe)
6318 results in 4855 files InstallerType: wix (msi)
5931 results in 5387 files InstallerType: inno
5664 results in 3754 files InstallerType: exe
2713 results in 1974 files InstallerType: msi
1004 results in 637 files InstallerType: burn (exe)
811 results in 688 files InstallerType: portable
448 results in 290 files InstallerType: msix
225 results in 217 files InstallerType: zip

Proposed technical implementation details

It's possible to run winget in the system context already, the sample code is below.

All I'm asking is for the winget-cli development team to recognise this, ensure this is a support method of running it, by simply taking this use case into consideration when developing winget further to ensure this type of usage does not break anything.

Possibly even ensure the system context executable is added to the machine PATH environment variable.

#region CODE
$winget = $null
$DesktopAppInstaller = "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe"
$SystemContext = Resolve-Path "$DesktopAppInstaller"
if ($SystemContext) { $SystemContext = $SystemContext[-1].Path }
$UserContext = Get-Command winget.exe -ErrorAction SilentlyContinue
if ($UserContext) { $winget = $UserContext.Source }
elseif (Test-Path "$SystemContext\AppInstallerCLI.exe") { $winget = "$SystemContext\AppInstallerCLI.exe" }
elseif (Test-Path "$SystemContext\winget.exe") { $winget = "$SystemContext\winget.exe" }
else { return $false }
if ($null -ne $winget) { $winget }
# Logs $(env:LOCALAPPDATA)\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\LocalState\DiagOutputDir
& "$winget" install --id "7zip.7zip" --exact --silent --accept-source-agreements --accept-package-agreements | Out-String
#endregion
@cgerke cgerke added the Issue-Feature This is a feature request for the Windows Package Manager client. label Mar 6, 2023
@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs-Triage Issue need to be triaged label Mar 6, 2023
@stephengillie stephengillie removed the Needs-Triage Issue need to be triaged label Mar 6, 2023
@denelon denelon added the Issue-Docs It's a documentation issue that really should be on MicrosoftDocs label Mar 6, 2023
@denelon
Copy link
Contributor

denelon commented Mar 6, 2023

We also know about "InstallShield" and "Squirrel" as .exe-based installers. Unfortunately, we don't have a good way to detect Squirrel, and we have separate issues for both of those. The existing breakdown of enumerated installer types helps WinGet default to standard switches for install modes. It's not a silver bullet, but it does help in many cases.

We are investing more in the area around running WinGet via the system context and the different scenarios around installers. We will be documenting both the "In-Process" and "Out-of-Process" interfaces to help both MDM providers, developers, and enterprise users.

I added the "Issue-Docs" label to cover the documentation aspect and have retained the "Issue-Feature" label to indicate other work we may need to do to make calling WinGet in the system context "easier / better".

@denelon
Copy link
Contributor

denelon commented Mar 10, 2023

We're looking at having the PowerShell modules when run in System context to leverage the "In Process" COM APIs as a supported method to achieve the goal (from the above workaround).

I'd say it's not an officially supported workaround, but I'm not aware of anything that would break this any time soon. I certainly expect to have a fully supported method well in advance of anything changing.

If I hear of anything changing, I will certainly bring it up here as soon as possible.

@apcsb
Copy link

apcsb commented Mar 10, 2023

[I understand that it's not currently supported, yet for info and discussion]
I have tried running WinGet (1.4.10173) in System context on a Win11 22H2 CloudPC machine. It produced very surprising and different results to my Win10 home PC

image

image

image

(For text search indexing: those are VCRUNTIME140.dll, MSVCP140.DLL, VCRUNTIME140_1.dll not found error messages)

I've got them by manually elevating into system context with nircmd.exe elevatecmd runassystem cmd.exe , then going to winget directory and running winget.exe
(nircmd is similar to psexec)

The %ERRORLEVEL% is -1073741515, which is the same as I was getting from the scripts I was trying to run in system context in the first place.

Again, I understand, that officially WinGet is not supported [hopefully, yet] in System context, just to draw awareness, that it behaves differently on different systems. While researching the error, I've found that the Windows Terminal app developers had a similar one (microsoft/terminal#11529) - maybe worth talking to that team...

Needless to say it runs perfectly well in user context.

Cheers

@denelon
Copy link
Contributor

denelon commented Apr 5, 2023

Work in progress for PowerShell cmdlets running in system context:

@nialljenIT365
Copy link

nialljenIT365 commented May 14, 2023

Hi apcsb,

These messages are related the required entries not being in the SYSTEM PATH Variable.

For Winget current stable release (https://github.com/microsoft/winget-cli/releases/tag/v1.4.10173) you can add the following.

"C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_1.19.10173.0_x64__8wekyb3d8bbwe"
"C:\Program Files\WindowsApps\Microsoft.VCLibs.140.00.UWPDesktop_14.0.30704.0_x64__8wekyb3d8"

You still need to be aware of the health warning mentioned using Winget in the SYSTEM context depending on the types of applications you are attempting to deploy. Any well constructed msi with properly populated properties table and nothing wild in custom actions should be fine, EXEs and NULLSOFT your mileage may vary. APPX and MSIX should be user targeted and deployed in USER context.

@denelon
Copy link
Contributor

denelon commented Jun 29, 2023

Hello all, we've published Microsoft.WinGet.Client with the ability to run WinGet in the system context. It does require running in PowerShell 7 with "-MTA".

If anyone can confirm, I'd like to close this issue.

We still have several package specific issues regarding whether the installer works correctly with the given manifest in system context, but the manifest has fields for scope to help in many of these cases.

@denelon denelon added Needs-Author-Feedback Issue needs attention from issue or PR author PowerShell Issue related to WinGet PowerShell Module or cmdlet labels Jun 29, 2023
@apcsb
Copy link

apcsb commented Jun 30, 2023

But this is just a PowerShell module, right? What about WinGet.exe itself?

@dzaggiel
Copy link

Getting error

Hello all, we've published Microsoft.WinGet.Client with the ability to run WinGet in the system context. It does require running in PowerShell 7 with "-MTA".

If anyone can confirm, I'd like to close this issue.

We still have several package specific issues regarding whether the installer works correctly with the given manifest in system context, but the manifest has fields for scope to help in many of these cases.

to for me, getting error using psexec
image

@Banthaf0dder
Copy link

Banthaf0dder commented Apr 9, 2024

I am a bit worried that the v7 with -MTA requirements makes this unusable for me and I suspect many others. EMM's such as Intune, Workspace ONE, etc. may not be designed to make use of Powershell 7 and may not be able to be set to execute scripts with the -MTA parameter within their scripting and application management offerings. Most of the point of running this under system context is so it can be used with these sort of EMM systems.

@apcsb
Copy link

apcsb commented Apr 12, 2024

EMM's such as Intune, Workspace ONE, etc. may not be designed to make use of Powershell 7
Could you please elaborate on that? Why?

@Banthaf0dder
Copy link

EMM's such as Intune, Workspace ONE, etc. may not be designed to make use of Powershell 7
Could you please elaborate on that? Why?

The scripting mechanisms in them all call on powershell.exe in C:\Windows\System32\WindowsPowerShell\v1. 0\ and there is no option to change that to anything else.

@mdanish-kh
Copy link
Contributor

[Policy] Context-System

@microsoft-github-policy-service microsoft-github-policy-service bot added the Context-System Related to system context (nt authority/session 0) label Apr 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Context-System Related to system context (nt authority/session 0) Issue-Docs It's a documentation issue that really should be on MicrosoftDocs Issue-Feature This is a feature request for the Windows Package Manager client. Needs-Author-Feedback Issue needs attention from issue or PR author PowerShell Issue related to WinGet PowerShell Module or cmdlet
Projects
None yet
Development

No branches or pull requests

8 participants