Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong filename for shell extension installed in win11 #416

Open
Roadelse opened this issue Dec 26, 2024 · 0 comments
Open

Wrong filename for shell extension installed in win11 #416

Roadelse opened this issue Dec 26, 2024 · 0 comments

Comments

@Roadelse
Copy link

I'm trying to develop a shell extension via SharpShell in windows 11 following the demo "CountLines" in this CodeProject Article. I copied the code and build it in Release mode, everything works fine by now.

Then, I tried several methods to deploy the generated dll, such as regasm, srm or ServerManager, each method works. However, the Context Menu for txt files doesn't have a "CountLines" item. By the way, it works fine in ServerManager.exe test shell.

Then, I used ShellexView to check my extension, it does exist but its file path shows:
"C:\Windows\System32\D:/my/custom/path/shellext.dll" Why does this happen?

Here is my code and some results:

using System.IO;
using System.Runtime.InteropServices;

using System.Text;

using SharpShell;
using SharpShell.SharpContextMenu;
using SharpShell.Attributes;

using System.Windows.Forms;

/// <summary>
/// The CountLinesExtensions is an example shell context menu extension,
/// implemented with SharpShell. It adds the command 'Count Lines' to text
/// files.
/// </summary>
[ComVisible(true)]
[COMServerAssociation(AssociationType.ClassOfExtension, ".txt")]
public class CountLinesExtension : SharpContextMenu
{
    /// <summary>
    /// Determines whether this instance can a shell
    /// context show menu, given the specified selected file list
    /// </summary>
    /// <returns>
    /// <c>true</c> if this instance should show a shell context
    /// menu for the specified file list; otherwise, <c>false</c>
    /// </returns>
    protected override bool CanShowMenu()
    {
        //  We always show the menu
        return true;
    }

    /// <summary>
    /// Creates the context menu. This can be a single menu item or a tree of them.
    /// </summary>
    /// <returns>
    /// The context menu for the shell context menu.
    /// </returns>
    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 count the lines
        itemCountLines.Click += (sender, args) => CountLines();

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

        //  Return the menu
        return menu;
    }

    /// <summary>
    /// Counts the lines in the selected files
    /// </summary>
    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 output
        MessageBox.Show(builder.ToString());
    }
}

ServerManager.exe test shell

Install shellext server in ServerManager.exe

Weird filename in shellexview

However, in registry, its path seems right?

I have tried to use srm or regasm to register the dll, both of them show the same result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant