Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
204 views
in Technique[技术] by (71.8m points)

c# - reference a windows shell interface using .net 4.0

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();

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)).

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

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

If someone can guide it will really helpful.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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);

}

This script is by combining help from http://nerdynotes.blogspot.com/2008/06/vbnet-shell32-code-compiled-on-vista.html

and

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...