How to use Shell32 in a C # application?

What should I include in a C # application to get Shell32 to work?

Edit:

My application cannot recognize shell32. What links or lib should I include? I am trying to do this:

Shell32.Shell shell = new Shell32.Shell(); 

What I get as an error:

Error 1: Could not find the name of the type or namespace "Shell32" (are you missing the using directive or assembly references?)

+28
c # shell32
Apr 18 '11 at 20:21
source share
9 answers

Just add the link to Shell32.dll from the Windows\System32 and use it:

 Shell32.Shell shell = new Shell32.Shell(); shell.MinimizeAll(); 
+48
Apr 18 '11 at 20:35
source share

maybe this might help:

  • Right click project
  • Click Add reference
  • Click on the .COM tab in the Add reference dialog
  • Choose Microsoft Shell Controls and Automation
  • Click OK

your shell32 ready to use ...

+46
Sep 19 '13 at 12:32
source share

I know this thread is outdated, but I am posting it to those who have the same issue as me. The solution above does not compile under windows 8

Shell32.Shell shell = new Shell32.Shell (); <= this does not work with windows 8

Use the work below if you want your applications to run under windows 8.

 using Shell32; private Shell32.Folder GetShell32Folder(string folderPath) { Type shellAppType = Type.GetTypeFromProgID("Shell.Application"); Object shell = Activator.CreateInstance(shellAppType); return (Shell32.Folder)shellAppType.InvokeMember("NameSpace", System.Reflection.BindingFlags.InvokeMethod, null, shell, new object[] { folderPath }); } 
+26
Sep 26 '13 at 17:44
source share
  • Right-click your project in the solution explorer.
  • Select "Add Link ..." from the drop-down menu.
  • Click the Summary tab.
  • Change to the C: \ Windows \ System32 directory.
  • Select the file "shell32.dll". and click OK.

You now have the appropriate link to use Shell32.Shell.

+6
Feb 22 '13 at 19:29
source share

I assume that you are having trouble recognizing any calls, so I will bring you to this general article: http://www.codeproject.com/KB/shell/csdoesshell1.aspx

In addition, you will need to indicate the features of what does not work for you.

+2
Apr 18 '11 at 20:30
source share

The class shown below should help with some of the shell32 methods in C #. you must add the link "Command and automatic shell Microsoft Shell" with a link by clicking on the project.

 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace MusicMuttPrototype { public class clsShellFileInfo { public Exception errorException; public enum FileDetailInfo { Name = 0, Year = 15, Size = 1, Track_Number = 19, Type = 2, Genre = 20, Date_Modified = 3, Duration = 27, Date_Created = 4, Bit_Rate = 28, Date_Accessed = 5, Protected = 23, Attributes = 6, Camera_Model = 24, Status = 7, Date_Picture_Taken = 25, Owner = 8, Dimensions = 26, Author = 9, Not_used = 27, Title = 10, Not_used_file = 28, Subject = 11, //Not_used = 29, Category = 12, Company = 30, Pages = 13, Description = 31, Comments = 14, File_Version = 32, Copyright = 15, Product_Name_Chapter = 33, //Scripting Quicktest Profess11ional Page 63 Artist = 16, Product_Version = 34, Album_Title = 17, Retrieves_the_info_tip_inf = -1 } public string getFileDetails(string fileFolder, string filePath, FileDetailInfo infotype) { string strReturnval = ""; try { Shell32.Shell fileshell = new Shell32.Shell(); Shell32.Folder fileshellfolder = fileshell.NameSpace(fileFolder); Shell32.FolderItem Item = fileshellfolder.ParseName(filePath); strReturnval = fileshellfolder.GetDetailsOf(Item, (int)infotype); } catch (Exception ex) { errorException = ex; } return strReturnval; } } } 
+2
Dec 22 '13 at 9:50
source share

If you don’t need a full set of API calls, you might be better off creating a COM import stub class. Watch how Mike Ward, who wrote Desk Drive, did it.

http://mike-ward.net/2008/09/02/a-lean-method-for-invoking-com-in-c/ https://github.com/mike-ward/DeskDrive/blob/master/ src / DeskDrive / Shell32.cs

+1
Oct 19 '16 at 21:57
source share

The link to the actual shell32.dll is out of date. You will get errors in the .NET Framework 4+. Using the older .NET Framework only to use shell32.dll limits the capabilities of your program. In applications for Windows 7+ and the .NET Framework 4+, you should always use the .COM component instead. Right click on the project. Click Add Link. Click the .COM tab in the Add Link dialog box. Select Microso.ft Shell Controls and Automation. Click OK

0
Jul 09 '18 at 16:18
source share

Add a link to the Microsoft Shell Controls and Automation COM library in your project. Also, make sure that code using Shell32.Shell runs in a single-threaded apartment, for example by adding [STAThread] to Main .

0
Jan 17 '19 at 19:48
source share



All Articles