Click here to Skip to main content
Click here to Skip to main content

Shell Extensions for .NET Assemblies

By , 17 Nov 2005
 

About the Shell Extensions for .NET Assemblies

These shell extensions were written to help distinguish between .NET assemblies and Win32 libraries, as well as give extra information about the assemblies without having to drop to a command-prompt to use the SDK and CLR tools. These shell extensions function similar to the loader that makes both .NET and VB (pre-.NET) possible as executable code: the PE/COFF header. As such, the library is very fast and won't hinder your file system browsing experience. A recent update further enhances performance by skipping assembly detection on slow paths, such as UNC paths or drive mappings to remote filesystems via VPN.

Provided in this library are:

  1. Overlay icons for .NET assemblies (.dll)

    Overlay icon 

  2. Column handlers to show the public key token and specific type of .NET assemblies.

    Column handlers 

  3. Automation object for getting the above information in your own applications and libraries.

The Automation Object

Not only does this tool help you distinguish between .NET assemblies and Win32 applications and libraries, but it also provides you with a simple automation object that these shell extensions use.

To generate code from the type library, add a reference or #import the type library named "AsmShell 1.0 Type Library". Use the members of the IAssemblyInfo automation interface as follows:

  • IAssemblyInfo::IsAssembly([in]BSTR path, [out, retval]VARIANT_BOOL* retVal)
    Returns true if the specified file is an assembly, false if it is not, and raises errors when problems occur.
  • IAssemblyInfo::GetFileType([in]BSTR path, [out, retval]FileType* retVal)
    Returns a FileType enumeration member depending on the information for the specified file in the PE/COFF header.
  • IAssemblyInfo::GetPublicKeyToken([in]BSTR path, [out, retval]BSTR* retVal)
    Returns the public key token for the specified assembly.
  • IAssemblyInfo::GetPublicKey([in]BSTR path, [out, retval]SAFEARRAY(BYTE)* retVal)
    Returns the public key as a byte array for the specified assembly. This is not supported by JScript or VBScript, both of which only support an array of VARIANTs.

For each method, late-binding languages like Visual Basic will use the return value (marked with [out, retval]) as the return type of the method, also getting rid of the need for the parameter labeled with the specified attributes above.

So, in VB6 and .NET (C#, VB.NET, et. al.), the methods signatures would look like:

bool IsAssembly(string path);
FileType GetFileType(string path);
string GetPublicKeyToken(string path);
byte[] GetPublicKey(string path);

Requirements

You may be required to reboot if files being installed are currently loaded. If you have Windows XP and the previous condition is false, no reboot should be necessary. If you're using Windows 98, ME, or 2000, you should either log off and back on or reboot your system if the overlay icon is not present; the column handlers should be ready immediately after the installation is finished.

Changes

  • November 17, 2005
    • Note: late article update for an earlier release
    • Added support to display x86 (and MSIL) for assemblies, as well as IA64 and x64
  • May 30, 2005
  • August 29, 2004
    • Added localizability
    • String caching for better performance
    • Support for .NET modules (.netmodule)
  • October 15, 2003
    • Added condition that files should not be parsed for slow paths (ex: VPN)
  • September 19, 2002
    • Initial release to the web on The Code Project

Disclaimer

THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR HIS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)

About the Author

Heath Stewart
Program Manager Microsoft
United States United States
Member
Heath Stewart is a happily married software engineer originally from the Midwest and a graduate of Iowa State University. Heath start programming early in life and enjoys continuous research and development in new languages, frameworks, and platforms. Fluent in many different programming languages, he has developed many large-scale software solutions for companies in different areas, such as Internet filtering, intrusion detection systems, production management systems, and web applications for various purposes. He also enjoys photography.
 
Currently, Heath is a Program Manager in the Visual Studio Professional Deployment Experience (VSPro DEX) team at Microsoft. Previous to his employment, he was a Microsoft MVP for Visual C#.
 
He is also a CodeProject protector and is happy to help the development community.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralRe: Icon LocationmemberSameers (theAngrycodeR )26 Sep '05 - 10:23 
Thank you very much for your information. I have written this code in C# .NET (2005) and your descriptions says that there is no way to point icon on specific location (like original icon is of 32*32 and my overlay icon is of 8*8 which I wanted to point on bottom left corner). It also looked to me the same as well as I couldnt find any hint in MSDN and other locations on the net. However, your idea looks interesting regarding getting icon from resource. Thanks again,
 
Sameers
AnswerRe: Icon LocationprotectorHeath Stewart26 Sep '05 - 11:15 
You need to make the overlay icon 32x32 and then you can position your non-transparent pixels anywhere. Open my overlay icon in VS and view the 32x32 pixel icon and you'll see the ".net" portion is in the corner. Move that to another portion of the 32x32 icon.
 
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft
 
[My Articles] [My Blog]
GeneralRe: Icon LocationmemberSameers (theAngrycodeR )26 Sep '05 - 11:19 
Yes, that is the same I got from your last reply. We need to design our icon in such way so that it displayed on the desired location (as your current icon of ".net" is displayed on bottom right, but the icon should be changed to display it on top left, no change in the code itself).
 
Sameers
AnswerRe: Icon LocationprotectorHeath Stewart26 Sep '05 - 11:25 
And I'm not telling you to change your code, just change the position of the non-transparent pixels. Your overlay icons should match in size to the icon you're overlaying, so that if the current icon for a file type is 32x32, you'd have a 32x32 icon resource. If it's both 32x32 and 24x24, then you'd use a .ico file with both sizes. Windows will pick the correct size or default to the next smaller size if the right size is not provided. If all you're using is an 8x8 icon then you won't have control over where it's position. Make a .ico file with different sizes of icons; remember that a single .ico can contain different resolutions and pixel depths. Open my .ico up in VS or another icon editor. If in VS, use the Image -> Current Icon Image Types menu to change the size and depth of the displayed icon.
 
By defining different icon types that match the size of the icon on which you want to overlay your icon you can control how your overlay displays because you can control where within its bounding region the non-transparent pixels are.
 
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft
 
[My Articles] [My Blog]
GeneralSoftware Design Engineer...memberbcraun1 Jun '05 - 8:35 
Software Design Engineer
Developer Division Customer Product-lifecycle Experience

 
Does that fit on a standard business card? Really, your title sounds interesting, what do you really do at MS? Smile | :)
 
Regards,
-bill
GeneralRe: Software Design Engineer...protectorHeath Stewart1 Jun '05 - 11:34 
Most developers here are called "Software Design Engineers", or simply "SDEs". DDCPX focuses on post-RTM releases (patches, services packs, etc.) as well as post-release tools for enterprise customers as well as home users. We also include the folks that bring you things like http://forums.microsoft.com/msdn[^].
 
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft
 
[My Articles] [My Blog]
GeneralOverlay IconmemberZenly17 Jan '05 - 10:07 
Hi,
 
I would like to add an icon overlay to selected files? I was hoping I would be able to reference it such as...
 
1, SetIconOverlay("MyFile.txt", "myOverlay.ico") ' to set the overlay icon.
 
2, GetIconOverlay("MyFile.txt") ' to get the overlay icon name associated with a file.
 
3, RemIconOverlay("MyFile.txt") ' to remove the overlay icon associated with a file.
 
Can I accomplish this with your shell extention?
 
Any Assistance would be greatly appreciated.
 
Zenly,
GeneralRe: Overlay IconprotectorHeath Stewart17 Jan '05 - 10:41 
This shell extension looks for PE/COFF data that determines whether the file is a managed assembly. It does not set overlay icons and is not a general purpose overlay icon.
 
To implement such an overlay would not be a good idea. Every file class (that is, "*" in the registry) would require registration for your overlay icon, which means Explorer would query your icon handler for EVERY SINGLE FILE on the file system that appears in Explorer for the default folder views (other view servers may not query for such information). You would have to index file paths efficiently, too, using - perhaps - a Trie (pronounced "try") data structure for efficient lookups. Using managed code for such a task would additionally be a bad idea since you have several MBs of RAM in overhead and many more instructions to process (even once JIT'd to native code).
 
If you want overlay icons then I suggest you implement them for your file classes (types). If you want to write a general purpose text editor than save your files as text but with a different extension. Or, save them using ".txt" and write an overlay icon handler for ".txt" but not for all file classes. Even in native code this would drag-down a system.
 
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
 
[My Articles] [My Blog]
GeneralRe: Overlay IconmemberZenly17 Jan '05 - 12:57 
Thanks for that insite. I didn't realize that adding an overlay to a file could so taxing on a system.
If I did this, as you suggested, to my own file type could you give me an example or tell me where I could find an example of this?
 
Thanks,
Zenly
GeneralRe: Overlay IconprotectorHeath Stewart17 Jan '05 - 13:15 
If you look at my source you'll see I implement IShellIconOverlay, which is documented at http://msdn.microsoft.com/library/en-us/shellcc/platform/shell/reference/ifaces/ishelliconoverlay/ishelliconoverlay.asp[^]. This can be implemented in managed code but you must declare the interface as a COM interface first. This is not recommended, however, since - as I said before - the Framework has overhead of loading the runtime and quite a few classes into memory.
 
To read about how to implement shell extensions in native code (and just in general if you understand P/Invoke and COM interop in .NET), see Mike Dunn's The Complete Idiot's Guide to Writing Shell Extensions - Index[^].
 
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
 
[My Articles] [My Blog]

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130523.1 | Last Updated 17 Nov 2005
Article Copyright 2002 by Heath Stewart
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid