Is there a tool for exploring/testing COM objects?

前端 未结 4 1613
轻奢々
轻奢々 2020-12-05 11:16

I\'m trying to automate a process by using a COM object from Python (win32com), but I\'m not getting the expected results... Is there a tool to explore/test COM objects with

4条回答
  •  半阙折子戏
    2020-12-05 11:28

    I am exploring COM objects in PowerShell. Found this great recipe, provided by Jaap Brasser, which is easy to run and answered my question.

    Get a list of all Com objects available Posted by Jaap Brasser on June 27, 2013

    Note: This tip requires PowerShell 2.0 or above.

    Recently a question was posted on the PowerShell.com forums: How to get a full list of available ComObjects? This tip will show how fetch all of them from the registry.

    Here is the code that we can use to generate this list:

    Get-ChildItem HKLM:\Software\Classes -ErrorAction SilentlyContinue | Where-Object {
       $_.PSChildName -match '^\w+\.\w+$' -and (Test-Path -Path "$($_.PSPath)\CLSID")
    } | Select-Object -ExpandProperty PSChildName
    

    The first Cmdlet reads out a complete list of values from HKLM:\Software\Classes and then verifies if the following two conditions are true:

    • Does the object match the naming convention for a ComObject?
    • Does the registry key have a CLSID folder? Every registered ComObject should have a CLSID as a unique identifier. An example of the output generated by this command is as follows:

      AccClientDocMgr.AccClientDocMgr
      AccDictionary.AccDictionary
      Access.ACCDAExtension
      Access.ACCDCFile
      Access.ACCDEFile
      Access.ACCDTFile
      Access.ACCFTFile
      Access.ADEFile

    To make the process of discovering ComObject easier the following function can be used.

    function Get-ComObject {
    
        param(
            [Parameter(Mandatory=$true,
            ParameterSetName='FilterByName')]
            [string]$Filter,
    
            [Parameter(Mandatory=$true,
            ParameterSetName='ListAllComObjects')]
            [switch]$ListAll
        )
    
        $ListofObjects = Get-ChildItem HKLM:\Software\Classes -ErrorAction SilentlyContinue | Where-Object {
            $_.PSChildName -match '^\w+\.\w+$' -and (Test-Path -Path "$($_.PSPath)\CLSID")
        } | Select-Object -ExpandProperty PSChildName
    
        if ($Filter) {
            $ListofObjects | Where-Object {$_ -like $Filter}
        } else {
            $ListofObjects
        }
    }
    

    This function is available in the TechNet Script Gallery:

    http://gallery.technet.microsoft.com/Get-ComObject-Function-to-50a92047

提交回复
热议问题