DonationCoder.com Forum

Other Software => Developer's Corner => Topic started by: Vurbal on March 20, 2014, 10:33 AM

Title: Interesting tool for generating WMI queries
Post by: Vurbal on March 20, 2014, 10:33 AM
While I was searching for a way to read shortcut (lnk) file properties in C# (why no I haven't torn out _all_ my hair, but thanks for asking) I stumbled across a nice little GUI for generating WMI queries called WMI Code Creator. It can be used either to enumerate the WMI namespaces, classes, methods, and qualifiers on a given computer (local or remote) or to actually generate C#, VB.NET, or VBScript code for running queries against them via WSH.

http://technet.microsoft.com/en-us/magazine/2006.01.utilityspotlight.aspx (http://technet.microsoft.com/en-us/magazine/2006.01.utilityspotlight.aspx)

I haven't gotten around to testing the code at all, or even attempted to browse the WMI providers on a remote machine for that matter. And of course WSH is deprecated in favor of PowerShell anyway. At the very least, though, the WMI browsing functionality seems useful. There's also a PowerShell based WMI browser (http://powershell.org/wp/2013/03/08/wmi-explorer-from-the-powershell-guy/) that's probably more useful for that. Since PowerShell was introduced shortly before the end of my days as an IT monkey I can't seem to be bothered to put the time and effort into messing with it though.
Title: Re: Interesting tool for generating WMI queries
Post by: 4wd on March 20, 2014, 07:04 PM
There's the old Scriptomatic (https://www.microsoft.com/en-us/download/details.aspx?id=12028) v2.0 tool also:

Scriptomatic 2.0 isn’t limited to writing just VBScript scripts; instead, Scriptomatic 2.0 can write scripts in Perl, Python, or JScript as well.

AutoIt WMI Scriptomatic (http://www.autoitscript.com/forum/topic/10534-wmi-scriptomatic-tool-for-autoit/)
Scriptomatic4AutoHotkey (http://ahkscript.org/boards/viewtopic.php?f=6&t=2290)
Powershell Scriptomatic (http://technet.microsoft.com/en-us/library/ff730935.aspx)
ADSI Scriptomatic (http://technet.microsoft.com/en-us/scriptcenter/dd939958.aspx)

Probably a version for every language ...
Title: Re: Interesting tool for generating WMI queries
Post by: MilesAhead on March 21, 2014, 06:08 AM
WMI is slow compared to WinAPI calls.  But it can get around some hairy obstacles.  One example I ran into was getting the "home folder" of the program that owns the active window.  Just a hotkey convenience toy that gets the path of the executable that owns the window and chops it at the last '\'.  Easy except for 32 vs 64 bit clash.  The WinAPI calls match up with either 32 or 64 bit depending on the caller's compile.

WMI can get the answer whether the caller is 32 bit or 64 bit.  Not good for tight loops such as enumerating all the window owners.  But you can't have everything.  :)

Thanks to both of you for posting these links.  I'm sure I'll find some interesting stuff using these tools.  :)