【发布时间】:2012-08-22 14:19:23
【问题描述】:
我使用下面的代码来引用一个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 控件和自动化参考来引用 shell,即 Interop.Shell32 dll
如果有人可以指导,那真的很有帮助。
【问题讨论】:
-
它很老了,我认为指南没有改变,但谁知道呢。在该机器上运行 regedit.exe 并导航到 HKCR\Shell.Application。验证 CLSID 键值为 {13709620-C279-11CE-A49E-444553540000}
-
有更简单的解决方案,见stackoverflow.com/a/24967301/625349
标签: c# c#-4.0 windows-shell