Csharp/C#教程:使用.net 4.0引用Windows shell接口分享


使用.net 4.0引用Windows shell接口

我使用以下代码来引用shell DLL

Type t = Type.GetTypeFromProgID("Shell.Application"); Shell s = (Shell)Activator.CreateInstance(t); Console.WriteLine("success"); Console.ReadLine(); 

它在我的Windows 7开发机器上工作正常。但是当我尝试在Win 2003服务器上运行exe时,我得到了这个exception

 Unable to cast COM object of type 'System.__ComObject' to interface type 'Shell3 2.Shell'. This operation failed because the QueryInterface call on the COM compo nent for the interface with IID '{866738B9-6CF2-4DE8-8767-F794EBE74F4E}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)). 

我从C#获得了一些帮助:引用了一个Windows shell界面,但没有运气。

我使用Microsoft Shell控件和自动化引用引用shell,这是Interop.Shell32 dll

如果有人可以指导,那将非常有帮助。

好吧,这就是我解决问题的方法,因为它可以帮助某人

这就是我的新代码的样子

 Type t = Type.GetTypeFromProgID("Shell.Application"); dynamic shell = Activator.CreateInstance(t); //This is browse through all the items in the folder var objFolder = shell.NameSpace(@"\filesharesFilestest"); foreach (var item in objFolder.Items()) { //This is to get the file's comments for each files in the folderitem string file_version = objFolder.GetDetailsOf(item, 14).ToString(); Console.WriteLine(file_version); } 

这个脚本是通过https://nerdynotes.blogspot.com/2008/06/vbnet-shell32-code-compiled-on-vista.html的帮助结合起来的。

https://foro.h-sec.org/net/problemas-en-net/

第二个链接是西class牙语,我使用谷歌翻译用英语补充

感谢所有回复此问题的人

看看这个: http : //nerdynotes.blogspot.com/2008/06/vbnet-shell32-code-compiled-on-vista.html我认为这是同一个问题。

代替

 Type t = Type.GetTypeFromProgID("Shell.Application"); dynamic shell = Activator.CreateInstance(t); 

我用了

 var shell = (IShellDispatch4) new Shell(); 

然后shell.Namespace按预期工作。

事实certificate,shell对象的引用默认为IShellDispatch5,不能在XP或2003中使用。

上述就是C#学习教程:使用.net 4.0引用Windows shell接口分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/1042915.html

(0)
上一篇 2022年1月31日
下一篇 2022年1月31日

精彩推荐