Click here to Skip to main content
15,887,940 members
Articles / Desktop Programming / ATL
Article

Shell Extensions for .NET Assemblies

Rate me:
Please Sign up or sign in to vote.
4.98/5 (29 votes)
17 Nov 2005Ms-PL3 min read 184.3K   2.6K   81   41
Shell extensions to distinguish between .NET assemblies and Win32 applications and libraries.

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:

C#
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)


Written By
Software Developer Microsoft
United States United States
Principal Software Engineer currently working on Azure SDKs at Microsoft. My opinions are my own. I work on a number of OSS projects for work and personally in numerous languages including C++, C#, JavaScript, Go, Rust, et. al. See a problem, fix a problem (or at least create an issue)!

Avid outdoor adventurer 🏔️❄️👞🚴‍♂️, husband, father.

Comments and Discussions

 
AnswerRe: Icon Location Pin
Heath Stewart26-Sep-05 11:25
protectorHeath Stewart26-Sep-05 11:25 
GeneralSoftware Design Engineer... Pin
bcraun1-Jun-05 8:35
bcraun1-Jun-05 8:35 
GeneralRe: Software Design Engineer... Pin
Heath Stewart1-Jun-05 11:34
protectorHeath Stewart1-Jun-05 11:34 
GeneralOverlay Icon Pin
Zenly17-Jan-05 10:07
Zenly17-Jan-05 10:07 
GeneralRe: Overlay Icon Pin
Heath Stewart17-Jan-05 10:41
protectorHeath Stewart17-Jan-05 10:41 
GeneralRe: Overlay Icon Pin
Zenly17-Jan-05 12:57
Zenly17-Jan-05 12:57 
GeneralRe: Overlay Icon Pin
Heath Stewart17-Jan-05 13:15
protectorHeath Stewart17-Jan-05 13:15 
GeneralRe: Overlay Icon Pin
hullion23-Nov-05 2:36
hullion23-Nov-05 2:36 
Surely your ShellExtension is being called for EVERY SINGLE FILE?

The reason I ask is that I am considering doing something like TortoiseCVS to produce Overlays on the file system based upon some additional meta-data that I will apply to them (the method or storing which is TBD). Although TortoiseCVS is very slow so I plan to build in some caching to improve performance as it does slow the file system down a lot.

If you are saying that performing this sort of operation is a bad thing then surely what you are doing is bad? Maybe just less bad as it is a quick operation. Ultimately you are querying the file everytime explore wants to draw it.

I have also noted your repeated points about not going through the CLR - I too am considering using it as my overlaying will be part of a larger system. Should a Microsoft employee really be playing down use of .NET? I can appreciate the additional memory overhead (a few megs?) but it isn't something that people usually worry about on a modern machine. As it is you aren't actually using what I would count as Native code it is still going through COM which is in itself a 'slow' technology. Ultimately COM and .NET are both built very heavily ontop of win32 which is what I would count as real native code.

That said I have been looking for a example of how to apply an overlay icon for a while, this gives me it and is EASY to follow. BUT where is the msi produced? Surely to be complete the source code download should include the setup project to allow us to recreate the msi files and also see how to do it ourselves for our own extensions - I have tried "regsvr32" and it installs but I don't get any overlays so I assume there are some additional steps that I can't see...

Thanks...

--
Phil

"No plan survive contact with the enemy"
AnswerRe: Overlay Icon Pin
Heath Stewart23-Nov-05 6:24
protectorHeath Stewart23-Nov-05 6:24 
GeneralDoesn't work on Win98! Pin
J. Dunlap15-Oct-03 9:40
J. Dunlap15-Oct-03 9:40 
GeneralRe: Doesn't work on Win98! Pin
Heath Stewart15-Oct-03 11:47
protectorHeath Stewart15-Oct-03 11:47 
GeneralRe: Doesn't work on Win98! Pin
J. Dunlap15-Oct-03 14:06
J. Dunlap15-Oct-03 14:06 
GeneralRe: Doesn't work on Win98! Pin
Heath Stewart30-May-05 11:46
protectorHeath Stewart30-May-05 11:46 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.