我正在使用以下代码来引用 shell dll
Type t = Type.GetTypeFromProgID("Shell.Application");
Shell s = (Shell)Activator.CreateInstance(t);
Console.WriteLine("success");
Console.ReadLine();
它在我的 Windows 7 开发机器上运行良好。但是当我尝试在 Win 2003 服务器上运行 exe 时,我得到了这个异常
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#: Referencing a windows shell interface 得到了一些帮助但没有运气。
我正在使用 Microsoft Shell Controls 和 Automation 引用 Interop.Shell32 dll 来引用 shell
如果有人可以指导,那将非常有帮助。
最佳答案
好的,这就是我解决问题的方法,因为它可以帮助别人
这就是我的新代码的样子
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/
第二个链接是西类牙语的,我用google翻译成英文的
感谢所有回答此问题的人
关于c# - 使用 .net 4.0 引用 Windows shell 接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12075188/