Click here to Skip to main content
15,867,453 members
Articles / Desktop Programming / Win32

.NET Shell Extensions - Shell Preview Handlers

Rate me:
Please Sign up or sign in to vote.
4.93/5 (23 votes)
20 May 2014MIT8 min read 139.5K   6.1K   71  
Quickly create Shell Preview Handlers for Windows or Outlook using .NET!
using System.Windows.Forms;
using SharpShell.Attributes;
using SharpShell.ServerRegistration;

namespace ServerManager.ServerDetails
{
    public partial class ServerDetailsView : UserControl
    {
        public ServerDetailsView()
        {
            InitializeComponent();
        }

        public void Initialise(ServerEntry serverEntry)
        {
            if (serverEntry != null)
            {
                textBoxServerName.Text = serverEntry.ServerName;
                textBoxServerType.Text = serverEntry.ServerType.ToString();
                textBoxServerCLSID.Text = serverEntry.ClassId.ToString();
                textBoxServerSecurity.Text = serverEntry.GetSecurityStatus();
                textBoxAssemblyPath.Text = serverEntry.ServerPath;

                //  Get the specified associations.
                var associationType = COMServerAssociationAttribute.GetAssociationType(serverEntry.Server.GetType());
                var associations = COMServerAssociationAttribute.GetAssociations(serverEntry.Server.GetType());
                textBoxAssociations.Text = associationType.ToString() + " " + string.Join(", ", associations);


                //  Now use the server registration manager to get the registration info
                //  for the different operating system architectures.
                var info32 = ServerRegistrationManager.GetServerRegistrationInfo(serverEntry.Server.ServerClsid, RegistrationType.OS32Bit);
                var info64 = ServerRegistrationManager.GetServerRegistrationInfo(serverEntry.Server.ServerClsid, RegistrationType.OS64Bit);

                //  By default, our installation info is going to be empty.
                textBox32BitServer.Text = "Not Installed";
                textBox64BitServer.Text = "Not Installed";

                //  Do we have 32 bit registration info?
                if (info32 != null)
                {
                    //  Do we have a codebase?
                    if (!string.IsNullOrEmpty(info32.CodeBase))
                        textBox32BitServer.Text = info32.CodeBase;
                    else if (!string.IsNullOrEmpty(info32.Assembly))
                        textBox32BitServer.Text = info32.Assembly + " (GAC)";
                }
                
                //  Do we have 32 bit registration info?
                if (info64 != null)
                {
                    //  Do we have a codebase?
                    if (!string.IsNullOrEmpty(info64.CodeBase))
                        textBox64BitServer.Text = info64.CodeBase;
                    else if (!string.IsNullOrEmpty(info64.Assembly))
                        textBox64BitServer.Text = info64.Assembly + " (GAC)";
                }
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The MIT License


Written By
Software Developer
United Kingdom United Kingdom
Follow my blog at www.dwmkerr.com and find out about my charity at www.childrenshomesnepal.org.

Comments and Discussions