in reply to Perl->WMI? (OT, I know)


This just came up the other day, see Win32::OLE made easy! and Scriptomatic.

Here is the code it produces for Win32_DisplayConfiguration:

use strict; use Win32::OLE('in'); use constant wbemFlagReturnImmediately => 0x10; use constant wbemFlagForwardOnly => 0x20; my @computers = ("MYPC"); foreach my $computer (@computers) { print "\n"; print "==========================================\n"; print "Computer: $computer\n"; print "==========================================\n"; my $objWMIService = Win32::OLE->GetObject("winmgmts:\\\\$computer\\ +root\\CIMV2") or die "WMI connection failed.\n"; my $colItems = $objWMIService->ExecQuery("SELECT * FROM Win32_Displ +ayConfiguration", "WQL", wbemFlagReturnImmediately | wbemFlagForwardOnly); foreach my $objItem (in $colItems) { print "BitsPerPel: $objItem->{BitsPerPel}\n"; print "Caption: $objItem->{Caption}\n"; print "Description: $objItem->{Description}\n"; print "DeviceName: $objItem->{DeviceName}\n"; print "DisplayFlags: $objItem->{DisplayFlags}\n"; print "DisplayFrequency: $objItem->{DisplayFrequency}\n"; print "DitherType: $objItem->{DitherType}\n"; print "DriverVersion: $objItem->{DriverVersion}\n"; print "ICMIntent: $objItem->{ICMIntent}\n"; print "ICMMethod: $objItem->{ICMMethod}\n"; print "LogPixels: $objItem->{LogPixels}\n"; print "PelsHeight: $objItem->{PelsHeight}\n"; print "PelsWidth: $objItem->{PelsWidth}\n"; print "SettingID: $objItem->{SettingID}\n"; print "SpecificationVersion: $objItem->{SpecificationVersion}\n" +; print "\n"; } }

I'm assuming (hopefully not wrongly) that you can set these properties as well as getting them.

--
John.

Replies are listed 'Best First'.
Re^2: Perl->WMI? (OT, I know)
by blueAdept (Beadle) on Feb 11, 2005 at 15:18 UTC
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_displayconfiguration.asp

    Looks like all the properties for that class are read-only. Another thing.. I'm 99% sure the WQL interface as microsoft affectionately calls their ODBC'ish interface to WMI can only be used to query information - you can't set things through it.(even if they're not read only) So if you're wanting to modify values or execute methods you must use the WMI object interface.

    Update: Here's a paste from MSDN A developer making a query to WMI must use the WMI Query Language (WQL). WQL is a subset of the ANSI standard Structured Query Language (SQL), with WMI-specific extensions. Because WQL is a read-only query language, a developer cannot use WQL to instruct the Windows Management service to update, insert, or delete data in the WMI repository or in a provider. Instead, a developer can only use WQL to retrieve information. For more information, see Querying WMI.
Re^2: Perl->WMI? (OT, I know)
by holli (Abbot) on Feb 11, 2005 at 20:32 UTC