Sign in to follow this  
Followers 0
Syed23

Doubt on WMI Querry

2 posts in this topic

Hi Everyone,

i have converted one of my WMI querry to AutoIT code and made it as UDF.

Here is the UDF

#include-once
Global $Title = "Power UDF"
Global $strComputer = @ComputerName, $GUIDActivePowerPlan, $GUIDSleepAfter, $PowerButtonAction, $FlagSet1, $LidAction, $FlagSet2, $GUIDHibernateAfter
Global $Power[2]
Global $objItem,$colItems,$objWMIService,$PowerButtonAction,$InstanceID


$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2\power")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PowerPlan WHERE IsActive = True", "WQL", 48)
For $objItem In $colItems
 $GUIDActivePowerPlan = StringSplit($objItem.InstanceID, "\", 1)
Next

Func Sleeptime()
 $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PowerSetting WHERE ElementName = 'Sleep after'", "WQL", 48)
 For $objItem In $colItems
  $GUIDSleepAfter = StringSplit($objItem.InstanceID, "\", 1)
 Next
 $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PowerSettingDataIndex WHERE InstanceID like '%" & $GUIDActivePowerPlan[2] & "%AC%" & $GUIDSleepAfter[2] & "'", "WQL", 48)
 For $objItem In $colItems
  $Power[0] = $objItem.SettingIndexValue
 Next
 
  $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PowerSettingDataIndex WHERE InstanceID like '%" & $GUIDActivePowerPlan[2] & "%DC%" & $GUIDSleepAfter[2] & "'", "WQL", 48)
  For $objItem In $colItems
   $Power[1] =  $objItem.SettingIndexValue
  Next
 
Return $Power
EndFunc   ;==>Sleeptime
Func PowerButton()
 $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PowerSetting WHERE ElementName = 'Power Button Action'", "WQL", 48)
 For $objItem In $colItems
  $PowerButtonAction = StringSplit($objItem.InstanceID, "\", 1)
 Next
  $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PowerSettingDataIndex WHERE InstanceID like '%" & $GUIDActivePowerPlan[2] & "%AC%" & $PowerButtonAction[2] & "'", "WQL", 48)
  For $objItem In $colItems
   $FlagSet1 = $objItem.SettingIndexValue
  Next
  $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PowerSettingDefinitionPossibleValue WHERE InstanceID like '%" & $PowerButtonAction[2] & "\\" & $FlagSet1 & "'", "WQL", 48)
  For $objItem In $colItems
   $Power[0] = $objItem.ElementName
  Next
 
  $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PowerSettingDataIndex WHERE InstanceID like '%" & $GUIDActivePowerPlan[2] & "%DC%" & $PowerButtonAction[2] & "'", "WQL", 48)
  For $objItem In $colItems
   $FlagSet1 = $objItem.SettingIndexValue
  Next
  $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PowerSettingDefinitionPossibleValue WHERE InstanceID like '%" & $PowerButtonAction[2] & "\\" & $FlagSet1 & "'", "WQL", 48)
  For $objItem In $colItems
   $Power[1] = $objItem.ElementName
  Next
 
 Return $Power
EndFunc   ;==>PowerButton
Func LidAction()
 $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PowerSetting WHERE ElementName = 'Lid close action'", "WQL", 48)
 For $objItem In $colItems
  $LidAction = StringSplit($objItem.InstanceID, "\", 1)
 Next
  $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PowerSettingDataIndex WHERE InstanceID like '%" & $GUIDActivePowerPlan[2] & "%AC%" & $LidAction[2] & "'", "WQL", 48)
  For $objItem In $colItems
   $FlagSet2 = $objItem.SettingIndexValue
  Next
  $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PowerSettingDefinitionPossibleValue WHERE InstanceID like '%" & $LidAction[2] & "\\" & $FlagSet2 & "'", "WQL", 48)
  For $objItem In $colItems
   $Power[0]= $objItem.ElementName
  Next
 
  $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PowerSettingDataIndex WHERE InstanceID like '%" & $GUIDActivePowerPlan[2] & "%DC%" & $LidAction[2] & "'", "WQL", 48)
  For $objItem In $colItems
   $FlagSet2 = $objItem.SettingIndexValue
  Next
  $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PowerSettingDefinitionPossibleValue WHERE InstanceID like '%" & $LidAction[2] & "\\" & $FlagSet2 & "'", "WQL", 48)
  For $objItem In $colItems
   $Power[1] = $objItem.ElementName
  Next
 
 Return $Power
EndFunc   ;==>LidAction
Func Hibernate()
 $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PowerSetting WHERE ElementName = 'Hibernate after'", "WQL", 48)
 Dim $InstanceID
 For $objItem In $colItems
  $GUIDHibernateAfter = StringSplit($objItem.InstanceID, "\", 1)
 Next
  $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PowerSettingDataIndex WHERE InstanceID like '%" & $GUIDActivePowerPlan[2] & "%AC%" & $GUIDHibernateAfter[2] & "'", "WQL", 48)
  For $objItem In $colItems
   $Power[0] = $objItem.SettingIndexValue
  Next
 
  $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PowerSettingDataIndex WHERE InstanceID like '%" & $GUIDActivePowerPlan[2] & "%DC%" & $GUIDHibernateAfter[2] & "'", "WQL", 48)
  For $objItem In $colItems
   $Power[1] =$objItem.SettingIndexValue
  Next
 
 Return $Power
EndFunc   ;==>Hibernate

when i use the UDF and run an example as below it works fine.

#include "Power.au3"
#include"Array.au3"
$test = Sleeptime()
_ArrayDisplay($test)

But here my problem is, when i add the same function into my huge code if i run exactly it fails when i call the function Sleeptime(). The error value is shows as 80041010 when i googled it i got the link. Does any one have any suggestion why i get this error message?


Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Share this post


Link to post
Share on other sites



please applogize me if i am getting hurried myself. does any one have a suggestion for above one?


Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

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
Sign in to follow this  
Followers 0