【问题标题】:Create IShellLibrary instance in PowerShell在 PowerShell 中创建 IShellLibrary 实例
【发布时间】:2012-01-11 08:54:27
【问题描述】:

如何在 PowerShell 中创建 IShellLibrary (http://msdn.microsoft.com/en-us/library/windows/desktop/dd391719(v=vs.85).aspx) 实例? IShellLibrary 接口使从代码管理@9​​87654322@ 成为可能。

Shell.Application COM 对象是否实现了IShellLibrary 接口?是否可以在 PowerShell 中将 shell 对象转换为 IShellLibraryinstance?以下是如何在 PowerShell 中创建 Shell.Application 实例的示例:

New-Object -ComObject Shell.Application

当我尝试投射对象时,结果是:

PS C:\Users\knut> [IShellLibrary](New-Object -ComObject Shell.Application)
Unable to find type [IShellLibrary]: make sure that the assembly containing this type is loaded.
At line:1 char:16
+ [IShellLibrary] <<<< (New-Object -ComObject Shell.Application)
    + CategoryInfo          : InvalidOperation: (IShellLibrary:String) [], RuntimeException
    + FullyQualifiedErrorId : TypeNotFound

IShellLibrary 接口在哪里?如何将其导入 PowerShell 会话?

【问题讨论】:

    标签: windows com powershell


    【解决方案1】:

    您可以通过调用SHCreateLibrary 来获取IShellLibrary,这会创建一个空的。如果您想要现有文件夹的IShellLibrary,则需要SHLoadLibraryFromParsingName 或其他相关功能之一。它们列在IShellLibrary 页面的底部。

    看来您需要使用 P/Invoke 从 PowerShell 调用它们。

    更新

    http://www.leeholmes.com/blog/2009/01/19/powershell-pinvoke-walkthrough/

    【讨论】:

    • 您能否提供一个有关如何将 P/Invoke 与 IShellLibrary 一起使用的 PowerShell 示例?
    猜你喜欢
    • 1970-01-01
    • 2014-09-05
    • 2017-06-16
    • 1970-01-01
    • 2016-06-24
    • 1970-01-01
    • 1970-01-01
    • 2021-11-16
    • 1970-01-01
    相关资源
    最近更新 更多