使用.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(@"\\fileshares\Files\test"); 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); } 

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

http://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中使用。