windows 是否有用于探索/测试 COM 对象的工具?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3940498/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 07:40:16  来源:igfitidea点击:

Is there a tool for exploring/testing COM objects?

windowscomoleview

提问by Joril

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 without having to write a specific program? I mean, is there something that allows e.g. to instantiate a COM object and call its methods?

我正在尝试通过使用 Python (win32com) 中的 COM 对象来自动化一个过程,但我没有得到预期的结果......是否有一种工具可以在无需编写特定程序的情况下探索/测试 COM 对象?我的意思是,有什么东西可以让例如实例化一个 COM 对象并调用它的方法吗?

(Basically I'm trying to find out if my unexpected results are win32com's fault, and I'd like to avoid installing Visual Studio to write a C# app)

(基本上我试图找出我的意外结果是否是 win32com 的错,并且我想避免安装 Visual Studio 来编写 C# 应用程序)

采纳答案by Joril

For the record, I ended up writing a very small script using SciTe4AutoHotKeyand AutoHotKey COM wrappers, no .Net required.
(and my unexpected results weren't Python's fault :) )

作为记录,我最终使用SciTe4AutoHotKeyAutoHotKey COM 包装器编写了一个非常小的脚本,不需要 .Net。
(我的意外结果不是 Python 的错:))

回答by tyranid

I actually wrote a replacement for the SDK tool OleView (afaik it doesn't support calling methods only enumerating) unimaginatively called OleViewDotNet. You can get the source code herebut as you'd need to compile it's likely it would be quicker to write the simple C# program or use Powershell.

我实际上为 SDK 工具 OleView(它不支持仅枚举调用方法)编写了一个替代品,毫无想象力地称为 OleViewDotNet。您可以在此处获取源代码但由于您需要编译,因此编写简单的 C# 程序或使用 Powershell 可能会更快。

What it does do is expose IDispatch methods (and some native interfaces) via a GUI so you can call them and it also provides an IronPython script window. You'd need to find your COM object by looking under "Registry -> CLSID By Name", find the entry (the filter can be used to select by name part) right click and select "Create Instance" that should show up a window similar to:

它所做的是通过 GUI 公开 IDispatch 方法(和一些本机接口),以便您可以调用它们,它还提供了 IronPython 脚本窗口。您需要通过在“Registry -> CLSID By Name”下查找来找到您的 COM 对象,找到条目(过滤器可用于按名称部分选择)右键单击并选择应显示一个窗口的“创建实例”相似:

object information

对象信息

then select the "Operations" menu at the bottom and choose "Open Dispatch" to get the method/property window.

然后选择底部的“操作”菜单并选择“打开调度”以获取方法/属性窗口。

enter image description here

在此处输入图片说明

There's a lot more you can do with this but that's a simple overview.

你可以用它做更多的事情,但这是一个简单的概述。

回答by Chris Becke

If you download the Windows SDKvia the WebSetup you should be able to choose to just download the SDK tools. They include a program called Ole/COM Viewer (oleview.exe) that can be used to browse all registered COM objects, and for objects that support Ole Automation, open them and invoke methods.

如果您通过 WebSetup下载Windows SDK,您应该能够选择只下载 SDK 工具。它们包括一个名为 Ole/COM 查看器 (oleview.exe) 的程序,可用于浏览所有已注册的 COM 对象,对于支持 Ole 自动化的对象,打开它们并调用方法。

回答by Markus

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

我正在 PowerShell 中探索 COM 对象。找到了这个很棒的食谱,由 Jaap Brasser 提供,它很容易运行并回答了我的问题。

Get a list of all Com objects availablePosted 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

获取所有可用 Com 对象的列表Jaap Brasser 于 2013 年 6 月 27 日发布

注意:此提示需要 PowerShell 2.0 或更高版本。

最近,PowerShell.com 论坛上发布了一个问题:如何获取可用 ComObjects 的完整列表?这个技巧将展示如何从注册表中获取所有这些。

下面是我们可以用来生成这个列表的代码:

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

第一个 Cmdlet 从 HKLM:\Software\Classes 读出完整的值列表,然后验证以下两个条件是否为真:

  • 对象是否与 ComObject 的命名约定匹配?
  • 注册表项是否有 CLSID 文件夹?每个注册的 ComObject 都应该有一个 CLSID 作为唯一标识符。此命令生成的输出示例如下:

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

为了使发现 ComObject 的过程更容易,可以使用以下函数。

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
    }
}

此功能在 TechNet 脚本库中可用:

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