Jump to content

Difficulty on using ObjGet


Syed23
 Share

Recommended Posts

Hi Friends,

This is the first script i am trying to create COM. But i am facing some problem in OGJGET function. Could you please help me on that? For your reference i have my script below.

Please let me know if i have posted my question in wrong forum.

#RequireAdmin 
Global $objItem 
Dim $Output, $Output1, $arConversionStatus 
Dim $strComputer = "." 

$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2\Security\MicrosoftVolumeEncryption") 
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_EncryptableVolume", "", 48) 
If IsObj($colItems) Then 
$Output = $objItem.GetProtectionStatus 
$Output1 = $objItem.GetConversionStatus 
If $Output = "Protection On" Then 
$arConversionStatus = "YES" 
Else 
$arConversionStatus = "NO" 
EndIf 

If $Output1 > 0 Then 

$arConversionStatus = "EncryptionPercentage" 
EndIf 
EndIf 


MsgBox(0, "", $arConversionStatus)
Edited by Syed23

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

Link to comment
Share on other sites

The problem is not with ObjGet, but your script errors. Your ExecQuery syntax was wrong, and you must use the For-In-Next syntax with an object collection. Try:

SWbemServices.ExecQuery

#RequireAdmin
Global $objItem
Dim $Output, $Output1, $arConversionStatus
Dim $strComputer = "."

$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2\Security\MicrosoftVolumeEncryption")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_EncryptableVolume", "WQL", 48)
If IsObj($colItems) Then
    For $objItem In $colItems
        $Output = $objItem.GetProtectionStatus
        $Output1 = $objItem.GetConversionStatus
        If $Output = "Protection On" Then
            $arConversionStatus = "YES"
        Else
            $arConversionStatus = "NO"
        EndIf

        If $Output1 > 0 Then
            $arConversionStatus = "EncryptionPercentage"
        EndIf
        ; exit loop here since there is presumably only one object
        ; if you are expecting more than one object from your query
        ; handle it appropriately
        ExitLoop
    Next
EndIf

MsgBox(0, "", $arConversionStatus)
Edited by wraithdu
Link to comment
Share on other sites

Thanks for quick reply and the script was working perfect! Thans a lot.. can you explain me how it works ?

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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...