Jump to content
Javik

Access COM interface IDiskQuotaUser ?

Recommended Posts

Javik

Is there a way to read data directly from the Windows Component Object Model (COM) interface?

I am trying to make a really simple disk space reporter tool for accounts on an Active Directory domain, to read the disk quota limit for the logged on user's home directory, and report how much disk space they are currently using.

,

MSDN:  IDiskQuotaUser interface

https://msdn.microsoft.com/en-us/library/windows/desktop/aa365033(v=vs.85).aspx

GetQuotaLimit

GetQuotaUsed

 

 

Share this post


Link to post
Share on other sites
LarsJ

Yes, it should be possible. You should start by creating a DiskQuotaControl object with ObjCreateInterface. Initialize the object and use FindUserName to obtain a pointer to an IDiskQuotaUser interface. Create a DiskQuotaUser object and call GetQuotaLimit and GetQuotaUsed.

Here is some code to get started:

#AutoIt3Wrapper_UseX64=y ; <<<<<<<<<<<<<<<< You MUST use proper setting >>>>>>>>>>>>>>>>

#include <WinAPIDiag.au3>

Opt( "MustDeclareVars", 1 )

Global Const $sCLSID_DiskQuotaControl = "{7988B571-EC89-11CF-9C00-00AA00A14F56}"

Global Const $sIID_IDiskQuotaControl = "{7988B572-EC89-11CF-9C00-00AA00A14F56}"
Global Const $stag_IDiskQuotaControl = _ ; There's only added parameter types for used methods
  "Initialize hresult(wstr;bool);" & _
  "SetQuotaState hresult();" & _
  "GetQuotaState hresult();" & _
  "SetQuotaLogFlags hresult();" & _
  "GetQuotaLogFlags hresult();" & _
  "SetDefaultQuotaThreshold hresult();" & _
  "GetDefaultQuotaThreshold hresult();" & _
  "GetDefaultQuotaThresholdText hresult();" & _
  "SetDefaultQuotaLimit hresult();" & _
  "GetDefaultQuotaLimit hresult();" & _
  "GetDefaultQuotaLimitText hresult();" & _
  "AddUserSid hresult();" & _
  "AddUserName hresult();" & _
  "DeleteUser hresult();" & _
  "FindUserSid hresult();" & _
  "FindUserName hresult(wstr;ptr*);" & _
  "CreateEnumUsers hresult();" & _
  "CreateUserBatch hresult();" & _
  "InvalidateSidNameCache hresult();" & _
  "GiveUserNameResolutionPriority hresult();" & _
  "ShutdownNameResolution hresult();"

Global Const $sIID_IDiskQuotaUser = "{7988B574-EC89-11CF-9C00-00AA00A14F56}"
Global Const $stag_IDiskQuotaUser = _ ; There's only added parameter types for used methods
  "GetID hresult();" & _
  "GetName hresult();" & _
  "GetSidLength hresult();" & _
  "GetSid hresult();" & _
  "GetQuotaThreshold hresult();" & _
  "GetQuotaThresholdText hresult();" & _
  "GetQuotaLimit hresult(int64*);" & _
  "GetQuotaLimitText hresult();" & _
  "GetQuotaUsed hresult(int64*);" & _
  "GetQuotaUsedText hresult();" & _
  "GetQuotaInformation hresult();" & _
  "SetQuotaThreshold hresult();" & _
  "SetQuotaLimit hresult();" & _
  "Invalidate hresult();" & _
  "GetAccountStatus hresult();"


Example()

Func Example()
  Local $oErrorHandler = ObjEvent( "AutoIt.Error", "ErrorHandler" )

  ; Create DiskQuotaControl object
  Local $oDiskQuotaControl = ObjCreateInterface( $sCLSID_DiskQuotaControl, $sIID_IDiskQuotaControl, $stag_IDiskQuotaControl )
  If Not IsObj( $oDiskQuotaControl ) Then Return ConsoleWrite( "$oDiskQuotaControl ERR" & @CRLF )
  ConsoleWrite( "$oDiskQuotaControl OK" & @CRLF )

  ; Initialize DiskQuotaControl to C-drive with read-only access
  Local $hResult = $oDiskQuotaControl.Initialize( "C:\", False ) ; <<<<<<<<<<<<<<<< Add volume root >>>>>>>>>>>>>>>>
  If $hResult Then Return ConsoleWrite( "Initialize ERR: 0x" & Hex( $hResult ) & " (" & _WinAPI_GetErrorMessage( $hResult ) & ")" & @CRLF )
  ConsoleWrite( "Initialize OK" & @CRLF )

  ; Find user
  Local $pUser
  $hResult = $oDiskQuotaControl.FindUserName( "User name", $pUser ) ; <<<<<<<<<<<<<<<< Add user name >>>>>>>>>>>>>>>>
  If $hResult Then Return ConsoleWrite( "FindUserName ERR: 0x" & Hex( $hResult ) & " (" & _WinAPI_GetErrorMessage( $hResult ) & ")" & @CRLF )
  ConsoleWrite( "FindUserName OK" & @CRLF )

  ; Create IDiskQuotaUser object
  Local $oDiskQuotaUser = ObjCreateInterface( $pUser, $sIID_IDiskQuotaUser, $stag_IDiskQuotaUser )
  If Not IsObj( $oDiskQuotaUser ) Then Return ConsoleWrite( "$oDiskQuotaUser ERR" & @CRLF )
  ConsoleWrite( "$oDiskQuotaUser OK" & @CRLF )

  ; Quota limit
  Local $iLimit
  $hResult = $oDiskQuotaUser.GetQuotaLimit( $iLimit )
  If $hResult Then Return ConsoleWrite( "GetQuotaLimit ERR: 0x" & Hex( $hResult ) & " (" & _WinAPI_GetErrorMessage( $hResult ) & ")" & @CRLF )
  ConsoleWrite( "GetQuotaLimit OK" & @CRLF )
  ConsoleWrite( "$iLimit = " & $iLimit & @CRLF )

  ; Quota used
  Local $iUsed
  $hResult = $oDiskQuotaUser.GetQuotaUsed( $iLimit )
  If $hResult Then Return ConsoleWrite( "GetQuotaUsed ERR: 0x" & Hex( $hResult ) & " (" & _WinAPI_GetErrorMessage( $hResult ) & ")" & @CRLF )
  ConsoleWrite( "GetQuotaUsed OK" & @CRLF )
  ConsoleWrite( "$iUsed = " & $iUsed & @CRLF )
EndFunc

; Use an error handler under development. Eg. comma instead of semicolon
; in the interface description will be caught by such an error handler.
Func ErrorHandler( $oError )
  ConsoleWrite( @ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted!" & @CRLF & _
    "  err.number is: " & @TAB & "0x" & Hex($oError.number) & @CRLF & _
    "  err.windescription:" & @TAB & $oError.windescription & _
    "  err.description is: " & @TAB & $oError.description & @CRLF & _
    "  err.source is: " & @TAB & $oError.source & @CRLF & _
    "  err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
    "  err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
    "  err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
    "  err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
    "  err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF )
EndFunc

 

  • Like 1

Share this post


Link to post
Share on other sites
Javik

Wow, that's quite a complete "some code" sample there.  Thank you.

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

  • Similar Content

    • Bilgus
      By Bilgus
      ; NetFirewallPolicy2 COM UDF Library for AutoIt3
      ; AutoIt Version : 3.3.14.5
      ; Description ...: Windows Firewall Policy2 Interface, Provides access to the firewall policy for Windows Vista+
      Including Test Script 
      UDF:
      Test Script:
       
    • Bilgus
      By Bilgus
      I was Playing around With AutoIt this evening and wondered how hard it would be to get typeinfo like the COM Viewers do only using AutoIt
      Turns out it was pretty easy.
      A Few Notes:
      CAarray info is unfinished I didn't have any objects to test it on so I left it Limited.
      The Object must have IDispatch exposed (ITypeInfo is derivative)
      Its Just a proof of concept Run with it but don't carry scissors
      ITypeInfoCOM.au3
      ITypeInfoTest.au3
       
      Output IWebBrowserApp
       
      Output ObjCreate(MediaPlayer.MediaPlayer.1)
       
    • Bilgus
      By Bilgus
       IGroupPolicyObject interface
      ;;IGroupPolicyObject #RequireAdmin #include-once #include <WinAPIConstants.au3> ; $S_OK #include <WinAPIReg.au3> ;_WinAPI_GetRegKeyNameByHandle Global Enum $GPO_SECTION_ROOT = 0x0, $GPO_SECTION_USER, $GPO_SECTION_MACHINE Global Enum $GPO_OPEN_LOAD_REGISTRY = 0x1, $GPO_OPEN_READ_ONLY Global Enum $GPO_OPTION_DISABLE_USER = 0x1, $GPO_OPTION_DISABLE_MACHINE Global Enum $GPOTypeLocal = 0x0, $GPOTypeRemote, $GPOTypeDS, $GPOTypeLocalUser, $GPOTypeLocalGroup Global Const $sCLSID_GroupPolicyObject = "{EA502722-A23D-11D1-A7D3-0000F87571E3}" Global Const $sIID_IGroupPolicyObject = "{EA502723-A23D-11D1-A7D3-0000F87571E3}" Global Const $dtag_IGroupPolicyObject = _ "New hresult(wstr;wstr;dword);" & _ ; Creates a new GPO in the Active Directory with the specified display name. "OpenDSGPO hresult(wstr;dword);" & _ ; Opens the specified GPO and optionally loads the registry information. "OpenLocalMachineGPO hresult(dword);" & _ ; Opens the default GPO for the computer and optionally loads the registry information. "OpenRemoteMachineGPO hresult(wstr;dword);" & _ ; Opens the default GPO for the specified remote computer and optionally loads the registry information. "Save hResult(bool;bool;ptr;ptr);" & _ ; Saves the specified registry policy settings to disk and updates the revision number of the GPO. "Delete hresult();" & _ ; Deletes the GPO. "GetName hResult(wstr;int);" & _ ; Retrieves the unique name for the GPO. "GetDisplayName hResult(wstr;int);" & _ ; Retrieves the display name for the GPO. "SetDisplayName hresult(wstr);" & _ ; Sets the display name for the GPO. "GetPath hResult(wstr;int);" & _ ; Retrieves the path to the GPO. "GetDSPath hresult(dword;wstr;int);" & _ ; Retrieves the Active Directory path to the root of the specified GPO section. "GetFileSysPath hresult(dword;wstr;int);" & _ ; Retrieves the file system path (UNC format) to the root of the specified GPO section. "GetRegistryKey hresult(dword;handle);" & _ ; Retrieves a handle to the root of the registry key for the specified GPO section. "GetOptions hResult(dword*);" & _ ; Retrieves the options for the GPO. "SetOptions hresult(dword;dword);" & _ ; Sets the options for the GPO. "GetType hResult(dword*);" & _ ; Retrieves type information for the GPO being edited. "GetMachineName hResult(wstr;int);" & _ ; Retrieves the computer name of the remote GPO. "GetPropertySheetPages hresult(ptr;uint*);" ; Retrieves the property sheet pages associated with the GPO. Test() Func Test() Local $iResult Local $oIGroupPolicy Local $aGpoType[5] = ["Local", "Remote", "Active Directory", "LocalUser", "LocalGroup"] $oIGroupPolicy = ObjCreateInterface($sCLSID_GroupPolicyObject, $sIID_IGroupPolicyObject, $dtag_IGroupPolicyObject) While True If Not IsObj($oIGroupPolicy) Then ConsoleWrite("Failed To Retrieve Interface") $iResult = $E_NOINTERFACE ExitLoop Else ConsoleWrite("Success: " & ObjName($oIGroupPolicy, 1) & @CRLF) EndIf Local $sLoc, $sPath, $sName, $iType $tKey = DllStructCreate("handle hKey") $iResult = $oIGroupPolicy.OpenLocalMachineGPO(BitOR($GPO_OPEN_LOAD_REGISTRY, $GPO_OPEN_READ_ONLY)) If $iResult <> $S_OK Then ExitLoop $iResult = $oIGroupPolicy.GetDisplayName($sLoc, 65535) If $iResult <> $S_OK Then ExitLoop $iResult = $oIGroupPolicy.GetName($sName, 65535) If $iResult <> $S_OK Then ExitLoop ConsoleWrite($sLoc & " : " & $sName & @CRLF) $iResult = $oIGroupPolicy.GetPath($sPath, 65535) If $iResult <> $S_OK Then ExitLoop $iResult = $oIGroupPolicy.GetType($iType) If $iResult <> $S_OK Then ExitLoop ConsoleWrite($sPath & @CRLF) $iResult = $oIGroupPolicy.GetType($iType) If $iResult <> $S_OK Then ExitLoop ConsoleWrite("Type: " & $aGpoType[$iType] & @CRLF) $iResult = $oIGroupPolicy.GetRegistryKey($GPO_SECTION_USER, DllStructGetPtr($tKey)) If $iResult <> $S_OK Then ExitLoop ConsoleWrite(_WinAPI_GetRegKeyNameByHandle(DllStructGetData($tKey, "hKey")) & @CRLF) ExitLoop WEnd Return SetError($iResult, 0, ($iResult = $S_OK)) EndFunc ;==>Test Note: Not well tested..
    • Fenzik
      By Fenzik
       Hello all"
      I have curious problem with com object implementation of Sapi 5.1.
      In some cases }Some Voice engines] the metods for retrieve the voice parameters fails with error :Member not exists:.
      But the Retrieved Voice object can speak the given text, so It exists and work.
      Example of this type of Engine can be this one: http://download.kobavision.be/KobaSpeech3/KobaSpeech 3 With Vocalizer Serena - English (Great Britain).exe (can work as demo)
      So my question is> Is there some way to workaround or solve this issue?
      What i tryed:
      1. Typical use of Sapi.spvoice object:
      $oMyError = ObjEvent("AutoIt.Error","MyErrFunc"); Install a custom error handler
       
        $spvoice = ObjCreate("sapi.spvoice")
      for $voice in $spvoice.getvoices()
        msgbox(0, "Voice", $voice.getdescription())
      next
      Func MyErrFunc()
      $HexNumber = hex($oMyError.number, 8)
      Msgbox(0,"","We intercepted a COM Error !" & @CRLF &"Number is: " & $HexNumber & @CRLF &"Windescription is: " & $oMyError.windescription)
      SetError(1)
      Endfunc

      2. Implement workaround based on Nvda Screen reader sapi5 Library at https://github.com/nvaccess/nvda/blob/master/source/synthDrivers/sapi5.py
      Thys code in Pascal should work, so i tryed to reproduce it in Autoit.
      Pascal code just as example:
                   SOTokens:=SpVoice.GetVoices('','');
                   for i:=0 to SOTokens.Count-1 do
                   try
                        SOToken:=SOTokens.Item(I); s:=SOToken.GetDescription(0);
      end
      In Autoit I tryed it like this:
      $oMyError = ObjEvent("AutoIt.Error","MyErrFunc"); Install a custom error handler
        $spvoice = ObjCreate("sapi.spvoice")
      for $i = 0 to $spvoice.getvoices.count-1
      $name = $spvoice.getvoices.item($i).getdescription
      msgbox(0,"Voice", $name)
      next
      Func MyErrFunc()
      $HexNumber = hex($oMyError.number, 8)
      Msgbox(0,"","We intercepted a COM Error !" & @CRLF &"Number is: " & $HexNumber & @CRLF &"Windescription is: " & $oMyError.windescription)
      SetError(1)
      Endfunc
      Both of this methods returning same Error ("Member not exists.").
      Thanks a lot for help.
      Znefyg
    • gillesg
      By gillesg
      Hello,
       
      Is there a way to get all the properties and method of a COM object thru Autoit.
      I am looking in a way of display the imbricated structure of object and method.
       
      Example of COm objects are "itunes.application", "Shell.application" and so on.
      The idea is to have a code looking like
      $objtobrowse = objcreate("itunes.application") if isobj($objtobrowse) then $colItems = $objtobrowse.buildinproperty For $objItem In $colItems ConsoleWrite($objItem.<Name> & " - " & $objItem.<Value> & @CRLF) Next EndIf  
×

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.