choco icon indicating copy to clipboard operation
choco copied to clipboard

RefreshEnv broken on Windows 11 24H2 - missing wmic.exe

Open mwallner opened this issue 1 year ago • 4 comments

Checklist

  • [X] I confirm there are no unresolved issues reported on the Chocolatey Status page.
  • [X] I have verified this is the correct repository for opening this issue.
  • [X] I have verified no other issues exist related to my problem.
  • [X] I have verified this is not an issue for a specific package.
  • [X] I have verified this issue is not security related.
  • [X] I confirm I am using official, and not unofficial, or modified, Chocolatey products.

What You Are Seeing?

On the latest LTSC release of Windows 11, the "wmic" utility has been removed.

What is Expected?

RefreshEnv should work whether wmic is available or not

How Did You Get This To Happen?

Using choco on the latest Win11 24h2 family releases.

System Details

  • Operating System: Win11 24H2 LTSC
  • Windows PowerShell version: 5.1
  • Chocolatey CLI Version: 2.2.2
  • Chocolatey Licensed Extension version: -
  • Chocolatey License type:
  • Terminal/Emulator: powershell / conhost

Installed Packages

-

Output Log

-

Additional Context

No response

mwallner avatar Oct 03 '24 07:10 mwallner

Whoever stumbles upon this, note that usage of Update-SessionEnvironment still works - so if it's possible consider using PowerShell instead of .bat. (directly using refreshenv from a PowerShell script shouldn't be necessary anyway)

mwallner avatar Oct 18 '24 08:10 mwallner

I've updated the title as this is actually just in 24H2 Windows 11: https://techcommunity.microsoft.com/blog/windows-itpro-blog/wmi-command-line-wmic-utility-deprecation-next-steps/4039242.

The script isn't entirely broken without wmic installed, more it emits an error and then refreshes the environment for cmd.exe. This is different from when it's run inside of powershell.exe where it reports that you should import the module and then run it again. Perhaps the update should be to always warn that it doesn't work for PowerShell and then still do the refresh for cmd 🤷‍♂

corbob avatar Dec 20 '24 21:12 corbob

Temporary workaround - WMIC can be (re)installed on 24H2 from "Optional Features": System -> Optional Features -> Add an optional feature: "wmic" (Win+s: "optional features") -> Add an optional feature: "wmic"

references

dcavacec avatar Jan 30 '25 03:01 dcavacec

The addition of wmic in the RefreshEnv.cmd file was in the PR to fix https://github.com/chocolatey/choco/issues/1392.

corbob avatar Jun 10 '25 15:06 corbob

@AdmiringWorm @pauby I think we should prioritise getting this fixed, since wmic is going away in newer builds of Windows. I am going to suggest that we add this to the 2.5.0 milestone, and get it addressed.

gep13 avatar Jun 23 '25 07:06 gep13

I've done some tests on a Windows 7 VM (only one I have that has a version of PowerShell old enough to validate with), and on Windows 11 Sandbox. Both Windows PowerShell 2.0 and Windows PowerShell 5.1 pick up .ps1 files that are on the path and execute them if they exist. To solve this and maintain the fix for #1392, we can:

  1. Revert https://github.com/chocolatey/choco/pull/2756 to remove the usage of wvmic
  2. Add a new RefreshEnv.ps1 file that should be signed and deployed the same way that RefreshEnv.cmd is.

The new RefreshEnv.ps1 could include:

# Import the Chocolatey Profile that contains the necessary code to enable
# tab-completions to function for `choco`.
# Be aware that if you are missing these lines from your profile, tab completion
# for `choco` will not function.
# See https://ch0.co/tab-completion for details.
$ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
if (Test-Path($ChocolateyProfile)) {
  Import-Module "$ChocolateyProfile"
} else {
  # This should never be reached
  throw "There is no $ChocolateyProfile file"
}
# Call the alias so that it outputs that the environment has been updated.
refreshenv

The Windows 7/PowerShell 2 validation was done with a file that merely mimics the output as the profile does not completely load on PowerShell 2:

Image

I haven't checked the build, but I believe the addition of the RefreshEnv.ps1 file should be detected and reported by the Verify-PowerShellScripts task which will prompt it automatically to ensure the script is signed.

corbob avatar Jun 30 '25 16:06 corbob