Jump to content

COM Object Helper Function(s)


erifash
 Share

Recommended Posts

Here are some object helper functions I have been working on:

#cs
Uses a For...In loop to return the enumerated element (level in the code) of an object.
#ce

Func OBJin( $oObject, $iLevel = 1 )
    If not IsObj($oObject) Then
        SetError(1)
        Return ""
    EndIf
    If $iLevel < 1 Then
        SetError(2)
        Return ""
    EndIf
    Local $i = 1, $o
    For $o in $oObject
        If $i = $iLevel Then Return $o
        $i += 1
    Next
    SetError(3)
    Return ""
EndFunc
#cs
Returns the number of elements in an object.
#ce

Func OBJs( $oObject )
    If not IsObj($oObject) Then
        SetError(1)
        Return 0
    EndIf
    Local $i = 0, $o
    For $o in $oObject
        $i += 1
    Next
    If $i = 0 Then SetError(2)
    Return $i
EndFunc

Questions and comments are greatly appreciated! B)

Link to comment
Share on other sites

Here is an example if anyone is confused:

Func _GetProxy( $sPC = "." )
    Local $oWMI = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $sPC & "\ROOT\CIMV2"), $oProxy = OBJin($oWMI.ExecQuery("SELECT * FROM Win32_Proxy", "WQL", 0x10 + 0x20))
    Return $oProxy.ServerName
EndFunc
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...