c# - 使用 .net 4.0 引用 Windows shell 接口(interface)

标签 c# c#-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 时,我得到了这个异常

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/

相关文章:

c#-4.0 - C# 4. 0's new "命名参数”功能不应该被称为 "named arguments"吗?

c# - 防止按钮点击事件,根据条件向Listview添加行

c# - 如何先获取 Entity Framework 代码中的自增值

c# - Azure Windows 事件日志级别

c# - 从 shell 元数据属性获取变形视频的显示大小

c# - 如何为 windows7、wpf 构建自定义 shell?

c# - 使用 C# 的 Windows shell 扩展

c# - HttpContext.Current 在 Identity Framework 的方法中为 null

c# - 连接mysql和c#

.net - 如何从线程任务返回数据