Jump to content
Sign in to follow this  
Syed23

Difficulty on using ObjGet

Recommended Posts

Syed23

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]

Share this post


Link to post
Share on other sites
wraithdu

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

Share this post


Link to post
Share on other sites
Syed23

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]

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.