2011-12-02 172 views
0

如何在PowerShell中创建IShellLibraryhttp://msdn.microsoft.com/en-us/library/windows/desktop/dd391719(v=vs.85).aspx)实例? IShellLibrary接口可以从代码管理Windows 7 libraries在PowerShell中创建IShellLibrary实例

这个Shell.Application COM对象是否实现了IShellLibrary接口?是否有可能在PowerShell中将shell对象转换为IShellLibrary实例?下面是关于如何在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会话中?

回答

0

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

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

更新

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

+0

能否请您提供有关如何使用P /与IShellLibrary调用PowerShell的例子吗? – knut

+0

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