It is currently December 8th, 2021, 6:40 pm

WMIC is going away!

Tips and Tricks from the Rainmeter Community
User avatar
jsmorley
Developer
Posts: 22421
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

WMIC is going away!

Post by jsmorley »

Microsoft will very soon be deprecating / removing the command-line WMIC tool that let you query information about your system in a cmd.exe command window.

If you are using skins that made use of the WMIC tool to retrieve information, you should very quickly change them to use the built-in PowerShell commandlets that support accessing this kind of information using CimInstance.

https://docs.microsoft.com/en-us/powershell/scripting/learn/ps101/07-working-with-wmi?view=powershell-7.1

https://powershell.one/wmi/root/cimv2

So for instance:

Old method:

Code: Select all

[MeasureGetAdapter]
Measure=Plugin
Plugin=RunCommand
Program=WMIC
Parameter=path win32_VideoController get name
OutputType=ANSI
RegExpSubstitute=1
Substitute="(?siU)^Name.*([\S].*)$":"\1","#CRLF#":""
New method:

Code: Select all

[MeasureGetAdapter]
Measure=Plugin
Plugin=RunCommand
Program=PowerShell
Parameter=(Get-CimInstance -ClassName win32_VideoController -Property Name).Name
OutputType=ANSI
So in a skin like this:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
OnRefreshAction=[!CommandMeasure MeasureGetAdapter "Run"]

[Metadata]
Name=GetGraphicsAdapterPS
Author=JSMorley
Information=Retreives and displays the name of the primary display adapter in Windows using PowerShell and WMI
Version=May 21, 2021

[MeasureGetAdapter]
Measure=Plugin
Plugin=RunCommand
Program=PowerShell
Parameter=(Get-CimInstance -ClassName win32_VideoController -Property Name).Name
OutputType=ANSI

[MeterDisplay]
Meter=String
MeasureName=MeasureGetAdapter
FontSize=10
FontColor=255,255,255,255
FontWeight=600
Antialias=1

1.png
You do not have the required permissions to view the files attached to this post.
User avatar
SilverAzide
Rainmeter Sage
Posts: 1676
Joined: March 23rd, 2015, 5:26 pm

Re: WMIC is going away!

Post by SilverAzide »

:ThinkingBig This gets me to wondering... it would be nice to have a generic plugin that could query any WMI class and return a value, or perhaps a list of values. It's pretty simple matter to query these classes, and there's a ton of useful info there... The ROI is questionable, since features already in Rainmeter can get you about 99% of everything most users want.
Gadgets Wiki GitHub More Gadgets...
User avatar
Yincognito
Rainmeter Sage
Posts: 4108
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: WMIC is going away!

Post by Yincognito »

jsmorley wrote: May 21st, 2021, 2:02 pm Microsoft will very soon be deprecating / removing the command-line WMIC tool that let you query information about your system in a cmd.exe command window.
Hmm... I knew they would deprecate the Get-WMIObject (aka gwmi) PowerShell command at a future time (even wrote myself some commented notes about the required changes in the PS command line in my skins, when that time comes), but I guess this is much serious (and related) than I thought, since they decided to deprecate the CMD's WMIC command as well. I guess this has to do with the security / network considerations mentioned here.

That being said, it seems some sources suggest that the deprecation of Get-WMIObject in favor of Get-CIMInstance already happened. O.O Can anyone having a newer Win 10 than my "old" 1803 version (and similarly, an upgraded PowerShell version installed by default) confirm that Get-WMIObject doesn't work on such newer PowerShell platforms? I still had the gwmi -class syntax in my skins' PS commands, and although I easily changed it to gcim -classname today after seeing this, it would help finding out if the "old" gwmi -class won't actually work anymore on newer Windows.
User avatar
jsmorley
Developer
Posts: 22421
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: WMIC is going away!

Post by jsmorley »

Get-WmiObject still works fine on a totally current Windows 10

Windows 10 Pro (64-Bit)
Version 2009
Build 19043.1081
User avatar
Yincognito
Rainmeter Sage
Posts: 4108
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: WMIC is going away!

Post by Yincognito »

jsmorley wrote: July 4th, 2021, 9:26 am Get-WmiObject still works fine on a totally current Windows 10

Windows 10 Pro (64-Bit)
Version 2009
Build 19043.1081
Nice! Thanks for confirming this. I guess I'll keep the changes I made today, just in case, but it's good to know there isn't an urgency to release skins because things stopped working properly. ;-)
User avatar
death.crafter
Rainmeter Sage
Posts: 1208
Joined: April 24th, 2021, 8:13 pm

Re: WMIC is going away!

Post by death.crafter »

Yincognito wrote: July 4th, 2021, 9:34 am Nice! Thanks for confirming this. I guess I'll keep the changes I made today, just in case, but it's good to know there isn't an urgency to release skins because things stopped working properly. ;-)
Working with Windows 11 Preview too.

Windows 11 Home Single Language (64-bit)
Version: 21H2
Build: 22000.51
from the Realm of Death
User avatar
Yincognito
Rainmeter Sage
Posts: 4108
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: WMIC is going away!

Post by Yincognito »

death.crafter wrote: July 4th, 2021, 10:53 am Working with Windows 11 Preview too.

Windows 11 Home Single Language (64-bit)
Version: 21H2
Build: 22000.51
Excellent, thanks! :great:
User avatar
jsmorley
Developer
Posts: 22421
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: WMIC is going away!

Post by jsmorley »

SilverAzide wrote: May 22nd, 2021, 2:18 am :ThinkingBig This gets me to wondering... it would be nice to have a generic plugin that could query any WMI class and return a value, or perhaps a list of values. It's pretty simple matter to query these classes, and there's a ton of useful info there... The ROI is questionable, since features already in Rainmeter can get you about 99% of everything most users want.
I'm not sure this wouldn't be a candidate for a "generic" Powershell .ps1 script that you include with your skin. I imagine it could be made to accept parameters that you pass it in a RunCommand measure. Might be just a tad more "author/user" friendly as a plugin, but yes, the ROI is a bit questionable.

Keep in mind though, that WMI in general is not "fast", and I'd be hesitant to have it being executed once a second.
User avatar
Yincognito
Rainmeter Sage
Posts: 4108
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: WMIC is going away!

Post by Yincognito »

jsmorley wrote: July 6th, 2021, 11:13 amI imagine it could be made to accept parameters that you pass it in a RunCommand measure.
Using parameters from a PS script is easy and similar to Lua functions (e.g. $args[N], N>=0) and passing them from a RunCommand is easy as well, but it's a bit tricky to work with double quotes (I'm guessing because of CMD's particularities, more than PS' ones), so when I needed this approach I used single quotes (apostrophes) instead. Not sure how this would fit with gwmi or gcim syntax though, especially on more complex scenarios like a filter or a select.