reference a windows shell interface using .net 4.0

前端 未结 3 588
情深已故
情深已故 2020-12-11 16:54

I am using the following code to reference a shell dll

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

            Shell s = (Shell)Acti         


        
相关标签:
3条回答
  • 2020-12-11 17:22

    Instead of

    Type t = Type.GetTypeFromProgID("Shell.Application");
    
    dynamic shell = Activator.CreateInstance(t);
    

    I used

    var shell = (IShellDispatch4) new Shell();
    

    shell.Namespace then works as expected.

    Turns out that reference for a shell object defaults to IShellDispatch5, which can't be used in XP or 2003.

    0 讨论(0)
  • 2020-12-11 17:32

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

    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

    0 讨论(0)
  • 2020-12-11 17:32

    Have a look at this: http://nerdynotes.blogspot.com/2008/06/vbnet-shell32-code-compiled-on-vista.html I think it's the same issue.

    0 讨论(0)
提交回复
热议问题