一般来说,我对 COM 和 Windows 编程/脚本非常陌生。我想做的是编写 Windows Live Writer 脚本;根据文档,我可以打电话
$o = New-Object -c WindowsLiveWriter.Application
我需要先加载 TLB,所以我应该调用add-type
命令,不幸的是它失败了:
PS C:\Users\NoWhereMan> add-type windowslivewriter.application
Add-Type : c:\Users\NoWhereMan\AppData\Local\Temp\a7ifbimo.0.cs(1) : A namespace does not directly contain members such
as fields or methods
c:\Users\NoWhereMan\AppData\Local\Temp\a7ifbimo.0.cs(1) : >>> windowslivewriter.application
At line:1 char:9
+ add-type <<<< windowslivewriter.application
+ CategoryInfo : InvalidData: (c:\Users\NoWher...elds or methods:CompilerError) [Add-Type], Exception
+ FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand
Add-Type : Cannot add type. There were compilation errors.
At line:1 char:9
+ add-type <<<< windowslivewriter.application
+ CategoryInfo : InvalidData: (:) [Add-Type], InvalidOperationException
+ FullyQualifiedErrorId : COMPILER_ERRORS,Microsoft.PowerShell.Commands.AddTypeCommand
物有所值,我运行的是 Windows7 x64
EDIT:x64 是关键问题,我需要将 PSH 作为 x86 进程运行
Thanks
From help add-type
:
将 Microsoft .NET Framework 类型(类)添加到 Windows PowerShell 会话。
but windowslivewriter.application
不是 .NET 类型。
PowerShell (PSH) directly supports COM objects, you do not need to take any special steps to load the Type Library (TLB)1, just call the methods diretcly as given in the documentation http://msdn.microsoft.com/en-us/library/aa738851.aspx for the component. E.g.:
$lw = New-Object -com WindowsLiveWriter.Application
$lw.NetPost()
启动新的帖子编辑器。
摘要:你愿意not需要先加载TLB。
在 64 位 Windows 下,您可能需要确保正在运行 PSH 的 32 位实例(“x86”)才能执行此操作(取决于 Live Writer 组件是在进程内还是在进程外运行)。
1 Strictly speaking, this only applies to COM types that support scripting with IDispatch, but in practice there are few that don't.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)