Python win32com.client.Dispatch("WScript.Shell") 到底是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23500274/
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
What exactly does win32com.client.Dispatch("WScript.Shell")?
提问by petosorus
I was searching for a Python piece of code which would simulate keystrokes.
I stumble upon something using win32com.client.Dispatch("WScript.Shell")
.
I am not fan (at all) of Windows but it is to help a friend with automation of a game.
我正在寻找一段可以模拟击键的 Python 代码。我偶然发现了一些使用win32com.client.Dispatch("WScript.Shell")
. 我(根本)不是 Windows 的粉丝,但它是为了帮助朋友进行游戏自动化。
I got a problem, this works fine on notepad or firefox for example, it does write but not on his game.
In order to find wether it comes from his game or my automation I would like to have some details about win32com.client
and what really represents WScript.Shell
我遇到了一个问题,例如,这在记事本或火狐上运行良好,它可以写入但不能在他的游戏中写入。为了找出它是来自他的游戏还是我的自动化,我想了解一些细节win32com.client
以及真正代表什么WScript.Shell
Thank you all
谢谢你们
采纳答案by NorthCat
Some citations:
一些引文:
As we discussed previously, automation objects are COM objects that expose methods and properties using the IDispatch interface. So how do we use these objects from Python? The win32com.client package contains a number of modules to provide access to automation objects. This package supports both late and early bindings, as we will discuss.
To use an IDispatch-based COM object, use the method win32com.client.Dispatch(). This method takes as its first parameter the ProgID or CLSID of the object you wish to create. If you read the documentation for Microsoft Excel, you'll find the ProgID for Excel is Excel.Application, so to create an object that interfaces to Excel, use the following code:
正如我们之前所讨论的,自动化对象是使用 IDispatch 接口公开方法和属性的 COM 对象。那么我们如何使用 Python 中的这些对象呢?win32com.client 包包含许多模块以提供对自动化对象的访问。这个包支持后期和早期绑定,我们将讨论。
要使用基于 IDispatch 的 COM 对象,请使用 win32com.client.Dispatch() 方法。此方法将您希望创建的对象的 ProgID 或 CLSID 作为其第一个参数。如果您阅读 Microsoft Excel 的文档,您会发现 Excel 的 ProgID 是 Excel.Application,因此要创建与 Excel 接口的对象,请使用以下代码:
import win32com.client
xl = win32com.client.Dispatch("Excel.Application")
(from this)
(从这里)
The WSript.Shell object provides functions to read system information and environment variables, work with the registry and manage shortcuts. (from: 12)