Во-первых, следуя демонстрации «CountLines» в этом руководстве: https://www.codeproject.com/Articles/512956/NET-Shell- Расширения-Оболочка-Контекст-Меню,
Я скопировал код и собрал его в режиме выпуска, теперь все работает нормально.
Затем я попробовал несколько методы для развертывания сгенерированной dll, такие как regasm, srm или ServerManager, каждый метод работает. Однако в контекстном меню для текстовых файлов нет пункта «CountLines». Кстати, в тестовой оболочке ServerManager.exe оно работает нормально.
Затем я использовал ShellexView, чтобы проверить свое расширение, оно существует. Но путь к его файлу показывает:
"C:\Windows\System32\D:/my/custom/path/shellext.dll"
Почему это произошло?
Вот мой код и некоторые результаты:
Код: Выделить всё
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using SharpShell;
using SharpShell.SharpContextMenu;
using SharpShell.Attributes;
using System.Windows.Forms;
///
/// The CountLinesExtensions is an example shell context menu extension,
/// implemented with SharpShell. It adds the command 'Count Lines' to text
/// files.
///
[ComVisible(true)]
[COMServerAssociation(AssociationType.ClassOfExtension, ".txt")]
public class CountLinesExtension : SharpContextMenu
{
///
/// Determines whether this instance can a shell
/// context show menu, given the specified selected file list
///
///
/// true if this instance should show a shell context
/// menu for the specified file list; otherwise, false
///
protected override bool CanShowMenu()
{
// We always show the menu
return true;
}
///
/// Creates the context menu. This can be a single menu item or a tree of them.
///
///
/// The context menu for the shell context menu.
///
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;
}
///
/// Counts the lines in the selected files
///
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());
}
}
введите здесь описание изображения
Установите сервер Shellext в ServerManager.exe:
введите описание изображения здесь
Странное имя файла в Shellexview:
введите здесь описание изображения
Однако в реестре его путь кажется правильным?
введите здесь описание изображения
У меня есть пробовал использовать srm или regasm для регистрации dll, оба показывают один и тот же результат
Подробнее здесь: https://stackoverflow.com/questions/793 ... l-in-win11
Мобильная версия