3

I tried to implement a custom ShellExtension in Windows 8.1. Found that really good SharpShell tutorial.

[ComVisible(true)]
[COMServerAssociation(AssociationType.AllFiles)]
public class CountExtProvider : SharpContextMenu
{
    protected override bool CanShowMenu()
    {
        //  We will always show the menu.
        return true;
    }

    protected override ContextMenuStrip CreateMenu()
    {
        //  Create the menu strip.
        var menu = new ContextMenuStrip();

        //  Create a 'count lines' item.
        var itemCountLines = new ToolStripMenuItem
        {
            Text = "Count Lines"
        };

        //  When we click, we'll call the 'CountLines' function.
        itemCountLines.Click += (sender, args) => CountLines();

        //  Add the item to the context menu.
        menu.Items.Add(itemCountLines);

        //  Return the menu.
        return menu;
    }

    private void CountLines()
    {
        //  Builder for the output.
        var builder = new StringBuilder();

        //  Go through each file.
        foreach (var filePath in SelectedItemPaths)
        {
            //  Count the lines.
            builder.AppendLine(string.Format("{0} - {1} Lines",
              Path.GetFileName(filePath), File.ReadAllLines(filePath).Length));
        }

        //  Show the ouput.
        MessageBox.Show(builder.ToString());
    } 
}

I am in a Windows 8.1 RTM x64 environment, so I changed my build plattform to x64 in Visual Studio 2013 RC. Added a Key-File to sign my *.dll. But if I want to register my *.dll nothing happends:

regasm ShellExtensions.dll

The command line says registering was successful but in the context menu there is no entry. What I am doing wrong here? Does this work with Windows 8.1 no more?

Martin
  • 3,096
  • 1
  • 26
  • 46

1 Answers1

7

I had the same problem while using regasm.exe.
Furthermore there are many things to mention when registering an assembly through regasm.
For example you have to use the x64/x86 version of the regasm.exe, depending on your system.

  • x64: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\regAsm.exe
  • x86: C:\Windows\Microsoft.NET\Framework\v4.0.30319\regAsm.exe

After having so many problems, I switched to the ServerManager.exe, which is part of the SharpShell Tools. It can be downloaded on the project page.
The usage is quite easy:

  • Load the DLL with "Load server..."
  • Click on "Install Server (xYZ)"
  • And after that on "Register Server (xYZ)"

Restart the Windows Explorer and you should be done (not necessarily needed).

I fully agree with the point of the author of the mentioned tutorial:

The Server Manager Tool

The Server Manager Tool is my preferred approach for installing/uninstalling and registering/unregistering, at least during development, because it lets you install and register as separate steps. It will also let you specify whether you're installing/uninstalling etc in 32 bit or 64 bit mode.

Community
  • 1
  • 1
jAC
  • 5,195
  • 6
  • 40
  • 55
  • Good answer! I wrote the library and tool because regasm was giving me such a headache, so I'm glad to see that it's been of some use! – Dave Kerr Nov 25 '13 at 21:56
  • Hi @Dave Kerr, SharpShell is really awesome and filling a gap for .NET developers. I'm not having a too easy time getting it to work, do you mind having a look at this question: http://stackoverflow.com/questions/30351411/file-overlayicon-not-showing-in-explorer-but-in-openfiledialog. I would be really happy about a little hint ;) Cheers, Marc – Marc May 20 '15 at 13:41
  • @DaveKerr I was wanting to write a basic FileExplorer and found your code massively useful. However, I am new to the interop stuff and wondered if you could tell me which `SFGAOF` flags I need to use to show File and Folders but restrict showing thing like applications and special folders? Thanks for your time. – MoonKnight Apr 27 '16 at 10:19
  • @Killercam try getting the object attributes and checking for SFGAO_FILESYSANCESTOR – Dave Kerr May 01 '16 at 13:44