Jump to content
J0hn

error in WMI Query, but working?

Recommended Posts

J0hn

Hi

I've got a piece of code, it works (when ran as administrator is disables the automatic pagefile setting) But the application crashes afterwards.

Can sombody point me in a direction what I'm doing wrong?

 

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""

$oWMIService = ObjGet("winmgmts:\\" & @ComputerName & "\ROOT\CIMV2")
$colItems = $oWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem", "WQL")

If IsObj($colItems) Then
   For $objItem In $colItems
        $objItem.AutomaticManagedPagefile = False
        $objItem.Put_()
   Next
Else
   MsgBox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_ComputerSystem" )
EndIf

Error Message: Error: The requested action with this object has failed.

Edited by J0hn

Share this post


Link to post
Share on other sites
Rampantshadow

Hi J0hn,

I would suggest putting a COM Event catcher, this way if the Event is caught and has something done with it the program will not crash, even if nothing is done in the function the script will not crash.

Check out https://www.autoitscript.com/autoit3/docs/functions/ObjEvent.htm for more information.

Cheers,

Share this post


Link to post
Share on other sites
J0hn

Thx, I will have a look.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×