Dismas has asked for the wisdom of the Perl Monks concerning the following question:

Gentle Wizards

I'm searching everywhere I can think of for an answer, so I thought I might as well try here, too...

Can anyone direct me to WMI methods for setting things? So far in my search, all I've found in WMI is how to retrieve information; nothing to actually change information!

Specifically, I'd like to find ways to create methods to set Video refresh rate, horizontal and vertical resolution, and perhaps other stuff as well.

BTW, I'll be doing all this in Perl--that's my justification, however lame it may be, for posting this here.

Thanks, O wise ones!!

Dismas

Replies are listed 'Best First'.
Re: Perl->WMI? (OT, I know)
by jmcnamara (Monsignor) on Feb 11, 2005 at 15:02 UTC

    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.

      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: Perl->WMI? (OT, I know)
by blueAdept (Beadle) on Feb 11, 2005 at 15:11 UTC
    Have you checked out Microsoft's Platform and the WMI SDKs?

    The platform SDK used to contain a wealth of example perl scripts using Win32::OLE, although most of them dump rather than set information - they do show how to call & use methods though. Many of the properties accessible in the objects are read-only as per the APIs, so checkout the SDK(or MSDN online) as to whether the properties you're looking at are. Even if the properties are read-only there may be an object method that can be used to change the values.

    An example is Win32_Service - all the object properties are read-only, but there is a Change method that will allow you to change a services settings. (such as Startup=Automatic|Manual|Disabled, etc...)

    What specific classes/objects are you looking at working with & changing settings for? HTH.
      Dear bA,

      At present, the only things we seem to want to change are the video refresh rate and horizontal & vertical resolutions. Whether others will appear in future, I can't say for certain, but it seems likely.

      Thanks!

      Dismas
        In any scripting language I don't know what the advisable way would be to do what you want. Display settings are in the registry, so you could certainly set those items directly with Win32::Registry. That IMHO is risky though, if you happened to change the settings to something that is an invalid/bad combination of values who knows what might happen to the machines. I would check into perhaps some sort of group policy tool. If a policy/template could be leveraged I think that'd be the safest/best approach.