使用 .net 4.0 引用 windows shell 界面 [英] reference a windows shell interface using .net 4.0

查看:17
本文介绍了使用 .net 4.0 引用 windows shell 界面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用下面的代码来引用一个shell dll

I am using the following code to reference a shell dll

            Type t = Type.GetTypeFromProgID("Shell.Application");

            Shell s = (Shell)Activator.CreateInstance(t);


            Console.WriteLine("success");
            Console.ReadLine();

它在我的 Windows 7 开发机器上运行良好.但是当我尝试在 Win 2003 服务器上运行该 exe 时,我得到了这个异常

It works fine on my windows 7 development machine.But when I try running the exe on Win 2003 server I get this 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 界面 获得了一些帮助,但是没有运气.

I took some help from C#: Referencing a windows shell interface but no luck.

我正在使用 Microsoft Shell Controls 和自动化参考(Interop.Shell32 dll)来引用 shell

I am referencing shell using Microsoft Shell Controls and Automation reference which is Interop.Shell32 dll

如果有人可以指导它真的很有帮助.

If someone can guide it will really helpful.

推荐答案

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

Ok,this is how I got through the problem incase it helps someone

这就是我的新代码的样子

This is how my new code looks like

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(@"\filesharesFiles	est");

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/

第二个链接是西班牙语的,我用谷歌翻译补上英语

The second link is in spanish,I used google translate to make it up in English

感谢所有回答这个问题的人

Thanks to all who replied to this question

这篇关于使用 .net 4.0 引用 windows shell 界面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆