Jump to content
Sign in to follow this  
colombeen

[SOLVED] WMI: Retrieve out params from method

Recommended Posts

Hi guys,

I'm trying to get some information using WMI, from the Win32_EncryptableVolume class.

I exec my query, filter out the C-drive, but when I need more info using the objects methods, I only get 1 value back and I can't seem to retrieve the other out params that should be there.

A very minimal version of what I'm trying to do (no error checking etc, very basic). You need to start SciTE as admin or you won't see any results in the console!

#RequireAdmin
$strComputer = @ComputerName

$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\CIMV2\Security\MicrosoftVolumeEncryption")
$objWMIQuery = $objWMIService.ExecQuery("SELECT * FROM Win32_EncryptableVolume WHERE DriveLetter='C:'", "WQL", 0)

For $objDrive In $objWMIQuery
    ConsoleWrite("> " & $objDrive.GetConversionStatus() & @CRLF)
    ConsoleWrite("> " & $objDrive.GetConversionStatus().ConversionStatus & @CRLF)
    ConsoleWrite("> " & $objDrive.GetConversionStatus().EncryptionPercentage & @CRLF)
Next

The result from the console is : 

> 0
> 
>

What I'm expecting to get back is : 

> 0
> 0
> 0

When using powershell I get this (run as admin is required!!!) : 

PS C:\WINDOWS\system32> (Get-WmiObject -namespace "Root\cimv2\security\MicrosoftVolumeEncryption" -ClassName "Win32_Encryptablevolume" -Filter "DriveLetter='C:'").GetConversionStatus()
...
ConversionStatus     : 0
EncryptionFlags      : 0
EncryptionPercentage : 0
ReturnValue          : 0
...

All I seem to be getting is the ReturnValue when I use the method.

I've tried this on multiple methods, always ending up with the same result

Anyone here who has experience with this type of thing?

 

Greetz

colombeen

Edited by colombeen

Share this post


Link to post
Share on other sites

Try this:

global $a,$b,$c

$strComputer = @ComputerName
$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\CIMV2\Security\MicrosoftVolumeEncryption")
$objWMIQuery = $objWMIService.ExecQuery("SELECT * FROM Win32_EncryptableVolume WHERE DriveLetter='C:'", "WQL", 0)

For $objDrive In $objWMIQuery
    $res = $objDrive.GetConversionStatus($a,$b,$c)
    ConsoleWrite("> " & $res & @CRLF)
    ConsoleWrite("> " & $a & @CRLF)
    ConsoleWrite("> " & $b & @CRLF)
    ConsoleWrite("> " & $c & @CRLF)
Next
Exit

And here is the documentation:

uint32 GetConversionStatus(
  [out] uint32 ConversionStatus,
  [out] uint32 EncryptionPercentage,
  [out] uint32 EncryptionFlags,
  [out] uint32 WipingStatus,
  [out] uint32 WipingPercentage,
  [in]  uint32 PrecisionFactor
);

 

Share this post


Link to post
Share on other sites
On 17-8-2018 at 11:14 AM, Juvigy said:

Try this:

global $a,$b,$c

$strComputer = @ComputerName
$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\CIMV2\Security\MicrosoftVolumeEncryption")
$objWMIQuery = $objWMIService.ExecQuery("SELECT * FROM Win32_EncryptableVolume WHERE DriveLetter='C:'", "WQL", 0)

For $objDrive In $objWMIQuery
    $res = $objDrive.GetConversionStatus($a,$b,$c)
    ConsoleWrite("> " & $res & @CRLF)
    ConsoleWrite("> " & $a & @CRLF)
    ConsoleWrite("> " & $b & @CRLF)
    ConsoleWrite("> " & $c & @CRLF)
Next
Exit

 

I'll definitely try that out!

Edited by colombeen

Share this post


Link to post
Share on other sites

Mhhmmnn... Some of the values that I get back aren't what I'm expecting.

I'll just show you guys what I'm working on (FYI: it's far from ready, but the end result will be shared) : 

; newer version in latest post

When I run this the $intWipingStatus contains "-1", but in powershell I get this value "4294967295", while the documentation shows that it could only be an int between 0 and 3

https://docs.microsoft.com/en-us/windows/desktop/secprov/getconversionstatus-win32-encryptablevolume

 

Any idea?

Edited by colombeen

Share this post


Link to post
Share on other sites

Guessing it's not a very popular subject.

Another thing that frustrates me is the return value of the "IsAutoUnlockKeyStored"-method (I'm not talking about the out param, just the return value).

The documentation shows

uint32 IsAutoUnlockKeyStored(
  [out] boolean IsAutoUnlockKeyStored
);

And the return values should be 

Return code/value           Description
---------------------------------------------------
S_OK                        The method was successful.
0 (0x0)

FVE_E_NOT_ACTIVATED         BitLocker is not enabled on the volume. Add a key protector to enable BitLocker.
2150694920 (0x80310008)

FVE_E_NOT_OS_VOLUME         The method can only be run for the currently running operating system volume.
2150694952 (0x80310028)

But then why do I keep getting "-2144272376"

Is there some kind of conversion I'm forgetting or is MS just screwing me over? :D

Edited by colombeen

Share this post


Link to post
Share on other sites

-2144272376 converts to 0x80310008 (FVE_E_NOT_ACTIVATED)

MsgBox(0, '', '0x' & Hex(-2144272376))

 


"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Share this post


Link to post
Share on other sites
3 minutes ago, ripdad said:

-2144272376 converts to 0x80310008 (FVE_E_NOT_ACTIVATED)

MsgBox(0, '', '0x' & Hex(-2144272376))

 

YOU
ARE
A
LIFE
SAVER

 

But I'm still not sure what to do with the -1 I'm getting from the $intWipingStatus :-s

Edited by colombeen

Share this post


Link to post
Share on other sites

-1 in WMI usually means: UNKNOWN

In powershell...

4294967295 converts to 0xFFFFFFFF which usually means allow or enabled and 0x00000000 usualy means disabled.

Not 100% sure this is the case for your issue though.

 


"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Share this post


Link to post
Share on other sites
23 hours ago, ripdad said:

-1 in WMI usually means: UNKNOWN

In powershell...

4294967295 converts to 0xFFFFFFFF which usually means allow or enabled and 0x00000000 usualy means disabled.

Not 100% sure this is the case for your issue though.

 

I was coming to the same conclusion as well on the -1 being UNKNOWN in most cases.

I've added it to my array as the first item and just +1 the result I get for now :)

; newer version in latest post

If anyone who is using bitlocker could test this out (and post back the results), it would be greatly appreciated!

Edited by colombeen

Share this post


Link to post
Share on other sites

I've made some more changes. I'm hoping it will work (can't test it here, I'm not allowed to encrypt my system just yet).

If anyone is willing to test my script (doens't matter if your system is or isn't using bitlocker, you just need WinVista or newer), please let me know what the result was so that I can fix bugs etc before I implement it (and also share it here ofcourse)

Please run SciTE as admin, otherwise you won't see the errors etc in the console

; newer version in latest post

Also, I'm not sure if it's possible to read this information remotely because of safety precautions by MS.

This is my result : 

BitlockerDriveInfo.thumb.png.1b638669df3f6fd3afb7fbd8f9a80067.png

My console output :

!> GetConversionStatus      0x00000000
!> GetEncryptionMethod      0x00000000
!> GetKeyProtectors         0x00000000
!> GetLockStatus            0x00000000
!> GetProtectionStatus      0x00000000
!> IsAutoUnlockEnabled      0x80310008
!> IsAutoUnlockKeyStored    0x80310008

EDIT:

I had a little issue that the secondary pop-up didn't show because I forgot to change $test[0][11] to $test[0][12] when I added another item to the array.

Edited by colombeen
bugfix

Share this post


Link to post
Share on other sites

This is the output of your script:

!> GetConversionStatus        0x00000000
!> GetEncryptionMethod        0x00000000
!> GetKeyProtectors       0x00000000
!> GetLockStatus      0x00000000
!> GetProtectionStatus        0x00000000
!> IsAutoUnlockEnabled        0x80310019
!> IsAutoUnlockKeyStored  0x00000000
"C:\Documents and Settings\delchevs\Desktop\COM fixes\BitLocker.au3" (58) : ==> The requested action with this object has failed.:
$aResult[$iRow][1]  =   $aVolumeTypeMsg[$objDrive.VolumeType]
$aResult[$iRow][1]  =   $aVolumeTypeMsg[$objDrive^ ERROR

And if i run the example script from my first post i get:

> 0
> 1
> 100
>

I am using win7 and have bitlocker.

Share this post


Link to post
Share on other sites
; newer version in latest post

This is an attempt to fix the missing properties in Win7

Edited by colombeen

Share this post


Link to post
Share on other sites

Now it works.

C:|Operating System Volume|Unkown|Protected|Unlocked|False|False|Fully Encrypted|AES_256|100|Free Space Not Wiped||{Array}
{CF607D86-743D-4E29-8FF2-A49D0D7AB820}|Numerical password
{B1AA7EF7-AC39-4D21-A278-B12EA6AA5F2B}|Trusted Platform Module (TPM)
!> GetConversionStatus        0x00000000
!> GetEncryptionMethod        0x00000000
!> GetKeyProtectors       0x00000000
!> GetLockStatus      0x00000000
!> GetProtectionStatus        0x00000000
!> IsAutoUnlockEnabled        0x80310019
!> IsAutoUnlockKeyStored  0x00000000

 

Share this post


Link to post
Share on other sites

Awesome!

I'll still need to fix some things but I'm getting there :) 

EDIT:

I've added a few checks to make sure everything works fine, I'm not noticing alot of performance loss.

; newer version in latest post

 

Edited by colombeen

Share this post


Link to post
Share on other sites

I'm just having one last issue before I can post the "final" version in the example scripts

I need to add

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7

But the changes I need to make so that my script will still work is what I can't figure out.

This is the part that will show errors : 

If IsArray($aVolumeKeyProtectorID) And UBound($aVolumeKeyProtectorID) > 0 Then
    Local $aVolumeKeyProtectors[UBound($aVolumeKeyProtectorID)][2], $iKeyProtectorType

    For $i = 0 To UBound($aVolumeKeyProtectorID) - 1
        $aVolumeKeyProtectors[$i][0]        =   $aVolumeKeyProtectorID[$i]
        If _WMIMethodExists($objDrive, "GetKeyProtectorType") Then
            If $objDrive.GetKeyProtectorType($aVolumeKeyProtectorID[$i], $iKeyProtectorType) = 0 Then
                $aVolumeKeyProtectors[$i][1]=   $aKeyProtectorTypeMsg[$iKeyProtectorType]
            Else
                $aVolumeKeyProtectors[$i][1]=   "Unknown"
            EndIf
        Else
            $aVolumeKeyProtectors[$i][1]    =   "Unknown"
        EndIf
    Next
Else
    Local $aVolumeKeyProtectors             =   "None"
EndIf

I declare the $aVolumeKeyProtectors 2 times, which I know is wrong, even more so when you put it inside of a loop.

Any suggestions? I can't seem to figure it out

Share this post


Link to post
Share on other sites

It's easy if you know how to do it:

Local $aVolumeKeyProtectors
If IsArray($aVolumeKeyProtectorID) And UBound($aVolumeKeyProtectorID) > 0 Then
    Dim $aVolumeKeyProtectors[UBound($aVolumeKeyProtectorID)][2]
    Local $iKeyProtectorType
    ; ...
Else
    $aVolumeKeyProtectors             =   "None"
EndIf

 

Share this post


Link to post
Share on other sites
3 hours ago, LarsJ said:

It's easy if you know how to do it:

Local $aVolumeKeyProtectors
If IsArray($aVolumeKeyProtectorID) And UBound($aVolumeKeyProtectorID) > 0 Then
    Dim $aVolumeKeyProtectors[UBound($aVolumeKeyProtectorID)][2]
    Local $iKeyProtectorType
    ; ...
Else
    $aVolumeKeyProtectors             =   "None"
EndIf

 

Is it that simple? I'll try that out! Thx!

EDIT:

Just tried it, WORKS LIKE A CHARM! :D

 

I moved the script to the examples : 

 

Edited by colombeen

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Bhooshan
      I need to mute an ongoing call on Microsoft teams without activating the window. Teams allows us to mute using shortcut key Ctrl+Shift+m but only when the window is active.
      # Used set option as ongoing call can be with any person which leads to change in Title Name.
      AutoItSetOption ( "WinTitleMatchMode", 2 ) 
      # I am not clear with the control ID which will be good to use here and also the key combination of ^M       
      ControlSend ( "Microsoft Teams", "", "[CLASS:Intermediate D3D Window; INSTANCE:1]", "{ctrl down}")
       
      Can anyone help...!!! 
       

    • By TheXman
      Encryption / Decryption / Hashing
      Purpose
      Cryptography API: Next Generation (CNG) is Microsoft's long-term replacement for their CryptoAPI.  CNG is designed to be extensible at many levels and cryptography agnostic in behavior.  Although the Crypt.au3 UDF that is installed with AutoIt3 still works perfectly, the advapi32.dll functions that it uses have been deprecated.  This UDF was created to offer a replacement for the deprecated functions.  According to Microsoft, deprecated functions may be removed in future release.  Therefore, this UDF will be available when/if that happens.
      Description
      This UDF implements some of Microsoft's Cryptography API: Next Generation (CNG) Win32 API functions.  In its initial release, it implements functions to encrypt text & files, decrypt text and files, generate hashes, and the Password-Based Key Derivation Function 2 (PBKDF2) function.  The UDF can implement any of the encryption/decryption algorithms or hashing algorithms that are installed on the PC in which it is running.  Most, if not all, of the values that you would commonly use to specify that desired algorithms, key bit lengths, and other magic number type values, are already defined as constants or enums in the UDF file.
      To flatten the learning curve, there is an example file that shows examples of all of the major functionality.  This example file is not created to be an exhaustive set of how to implement each feature and parameter.  It is designed to give you a template or guide to help you hit the ground running in terms of using the functions.  I have tried to fully document the headers of all of the functions as well as the code within the functions themselves.    As of v1.4.0, there is also a Help file that includes all of the functions, with examples.
      Current UDF Functions
      _CryptoNG_3DES_CBC_DecryptData _CryptoNG_3DES_CBC_DecryptFile _CryptoNG_3DES_CBC_EncryptData _CryptoNG_3DES_CBC_EncryptFile _CryptoNG_AES_CBC_DecryptData _CryptoNG_AES_CBC_DecryptFile _CryptoNG_AES_CBC_EncryptData _CryptoNG_AES_CBC_EncryptFile _CryptoNG_CreateRSAKeyPair _CryptoNG_DecryptData _CryptoNG_DecryptFile _CryptoNG_EncryptData _CryptoNG_EncryptFile _CryptoNG_EnumAlgorithms _CryptoNG_EnumRegisteredProviders _CryptoNG_GenerateRandom _CryptoNG_HashData _CryptoNG_HashFile _CryptoNG_LastErrorMessage _CryptoNG_PBKDF2 _CryptoNG_Version  
      Related Links
      Cryptography API: Next Generation - Main Page
      Cryptography API: Next Generation - Reference
      Cryptography API: Next Generation - Primitives
      Cryptography API: Next Generation - Cryptographic Algorithm Providers
    • By Colduction
      Hi AutoIt Programmers!

      I've seen a code that gives Name of Group by writing it's group's SID, but this one response very slower than Windows Command-Line WMIC
       
      Func _GetLocalGroupName($sSID = 'S-1-5-18') $objWMIService = ObjGet ("winmgmts:\\" & @ComputerName & "\root\cimv2") $colItems = $objWMIService.ExecQuery('SELECT Name FROM Win32_Group where SID="' & $sSID & '"') For $GroupNames in $colItems MsgBox (0,"",$GroupNames.Name) ExitLoop Next EndFunc I don't want call and use any third-party programs even CMD, i just want use from Windows API, netapi32.dll or AutoIt Functions (Standalone).
      Do you have any idea to improve speed/performance of this code? I'll happy of your comments
       
       
       
      ====================== SOLOUTION by @Subz ======================
       
    • By RTFC
      The CodeScannerCrypterBundle (ca. 2.5 MB) contains the following UDFs and utilities:
      CodeScanner: analyse AutoIt script structure and content, identify potential issues, generate MCF data files CodeCrypter: front-end GUI for the MCF library, for script encryption (without storing the decryption key(s) in the script!) MetaCodeFile UDF (MCF library): for analysis and user-defined alterations of AutoIt script structure and content MCFinclude.au3: #include this UDF in any AutoIt script that you wish CodeCrypter to process AES.au3, by Ward; machine code UDF for AES encryption (32-bit, patched version) CryptoNG, by TheXman; encryption UDF using Bcrypt dll calls (32/64-bit; various algorithms) StoreCCprofile.au3/readCSdatadump.au3/helloworld.au3: auxiliary utilities and example script HowToCodeCrypt.pdf: a simple guide in five steps CodeCrypterFAQ.pdf: questions and answers, partly based upon exchanges in the CodeCrypter thread. Please follow the links for additional information.
    • By RTFC
      MetaCode offers a way to:
      separate a script's structure from its content remove all redundant definitions (globals and UDFs) change any content (and some structure) combine (new) structure and (new) content into a new script The most useful applications implemented so far are:
      Fast language translation (not just text strings, also variable names and UDF names) Obfuscation (vars and/or UDFs) Script Encryption (conditionals, calls, and macros) Encryption is powerful because the key is not stored anywhere; you can define it to be a user password, macro, environment spec/variable, server response, something you define yourself, or a combination thereof; anything goes, as long as it's not a fixed string or fixed value. More info in the CodeCrypter thread: ?do=embed' frameborder='0' data-embedContent>'?do=embed' frameborder='0' data-embedContent>>
      ?do=embed' frameborder='0' data-embedContent>
      But MetaCode has more potential than that; it allows you to tinker with any type of content separately, then rebuild a new version. So for example, you can have a single script structure and numerous different language modules you just plug in to create a new version in a different language.
      A brief Tutorial is here: MetaCode Tutorial.pdf
      The MCF library itself can be found in the CodeScannerCrypter bundle.
      And a little example how to use it for translating your GUI into a different language:
       UI_Translator.7z (new version that should work with the new version of Google Translate, see post #13 below)
       
       
      MCF.au3 is just the library plus the MCFinclude.au3 file you need to include in any script you wish to encrypt.
      There is no GUI here. However, I did write a separate front-end for it called CodeCrypter, which you can find here:
      ?do=embed' frameborder='0' data-embedContent>'?do=embed' frameborder='0' data-embedContent>>
      ?do=embed' frameborder='0' data-embedContent>
      MCF uses output generated by my CodeScanner version 2.8+, which you can find here:
      '?do=embed' frameborder='0' data-embedContent>>
      CodeScanner also depends on MCF.au3 now, as it can now call a few of its functions.
      I should also mention Ward's excellent AES.au3 UDFs used for the encryption and decryption calls,  which is now included in the CodeScannerCrypter bundle (thanks to Ward for allowing to include it). You can find the original (unpatched) version here:
      '?do=embed' frameborder='0' data-embedContent>>
      Note: you can replace the encryption/decryption calls with whatever algorithm you like (hint: the native <Crypt.au3> library is too slow for most purposes, better stick to machine code routines)
      So just to be clear:
      CodeScanner (v2.8+) needs MCF (earlier versions won't work!) CodeCrypter needs MCF (plus anything that MCF needs) MCF itself needs MCFinclude (part of MCF zip) MCF also needs readCSdatadump (part of the CodeScanner package, you need the latest version packaged with CodeScanner v2.8; earlier versions won't work!) both MCF and MCFinclude currently rely on AES.au3 by Ward So you basically need to download the whole bundle for any of it to work.
       
      If you have any questions, please start by reading the MCF Tutorial and the CodeCrypter FAQ (you can download the latter separately from the CodeCrypter thread).
      Next, read the extensive Remarks sections in MCF.au3, MCFinclude.au3, and CodeCrypter.au3
      If still no joy, then please post. However, I'm not online that often, and logged in to the forum even less, so response may take a while).
      RT
×
×
  • Create New...