### Enable and Get SharpShell Installation Logs Source: https://sharpshell.readthedocs.io/en/latest/installing/installing Configure SharpShell logging to file using srm, attempt installation, and then disable logging. Logs are typically saved in the TEMP directory. ```bash srm config LoggingMode File srm config LogPath '%TEMP%SharpShell.log' srm install srm config LoggingMode Disable ``` -------------------------------- ### Install SharpShell Server using srm (GAC) Source: https://sharpshell.readthedocs.io/en/latest/installing/installing Install the server assembly into the GAC using gacutil, then use srm install to register it as a SharpShell server. ```bash gacutil -i srm install ``` -------------------------------- ### Installing the SRM Source: https://sharpshell.readthedocs.io/en/latest/srm/srm Information on how to obtain and install the Server Registration Manager tool. ```APIDOC ## Installing the SRM You can get the tool from the ServerRegistrationManager NuGet Package. It is also available in all SharpShell Releases. ``` -------------------------------- ### Install SharpShell Server using regasm (GAC) Source: https://sharpshell.readthedocs.io/en/latest/installing/installing Install the assembly into the Global Assembly Cache (GAC) using gacutil, then register it as a COM server with regasm. ```bash gacutil -i ExampleContextMenuExtension.dll regasm ExampleContextMenuExtension.dll ``` -------------------------------- ### Install SharpShell Servers Source: https://sharpshell.readthedocs.io/en/latest/srm/srm Commands to register a server DLL, with options for codebase usage and architecture specification. ```bash srm install ``` ```bash srm install -codebase ``` ```bash srm install [-codebase] -os32 srm install [-codebase] -os64 ``` -------------------------------- ### Install SharpShell Server using srm (Codebase) Source: https://sharpshell.readthedocs.io/en/latest/installing/installing Install a SharpShell server using srm with the -codebase flag, allowing registration without GAC installation. ```bash srm install -codebase ``` -------------------------------- ### Install SharpShell Server using regasm (Codebase) Source: https://sharpshell.readthedocs.io/en/latest/installing/installing Register a SharpShell server as a COM server using regasm with the /codebase flag, suitable for servers not installed in the GAC. ```bash regasm /codebase ExampleContextMenuExtension.dll ``` -------------------------------- ### Installing / Uninstalling Servers Source: https://sharpshell.readthedocs.io/en/latest/srm/srm Commands for installing and uninstalling SharpShell servers using the srm.exe tool. ```APIDOC ## Installing / Uninstalling Servers ### Install Server ``` srm install ``` ### Install Server (without using the GAC) ``` srm install -codebase ``` ### Install Server (with specific bitness) ``` srm install [-codebase] -os32 srm install [-codebase] -os64 ``` ### Uninstall Server ``` srm uninstall ``` ``` -------------------------------- ### Install SharpShell NuGet Package Source: https://sharpshell.readthedocs.io/en/latest/extensions/propertysheetextension/propertysheetextension Use the NuGet Package Manager console to add the SharpShell package to your project. ```powershell Install-Package SharpShell ``` -------------------------------- ### Install SharpShell via NuGet Source: https://sharpshell.readthedocs.io/en/latest/extensions/deskband/deskband Use the NuGet Package Manager console to add the SharpShell dependency to your project. ```powershell Install-Package SharpShell ``` -------------------------------- ### Register Server with Correct Bitness Source: https://sharpshell.readthedocs.io/en/latest/installing/installing Use the appropriate regasm path or srm flags based on the system architecture. ```text C:\Windows\Microsoft.NET\Framework\v4.0.30319\regasm ``` ```text C:\Windows\Microsoft.NET\Framework64\v4.0.30319\regasm ``` ```text srm install -os32 ``` -------------------------------- ### Create FileTimesPropertySheet Server Class Source: https://sharpshell.readthedocs.io/en/latest/extensions/propertysheetextension/propertysheetextension Define the main extension class by deriving from SharpPropertySheet. Implement CanShowSheet to control visibility and CreatePages to return property page instances. ```csharp [ComVisible(true)] [COMServerAssociation(AssociationType.AllFiles)] public class FileTimesPropertySheet : SharpPropertySheet { protected override bool CanShowSheet() { // We will only show the resources pages if we have ONE file selected. return SelectedItemPaths.Count() == 1; } protected override IEnumerable CreatePages() { // Create the property sheet page. var page = new FileTimesPropertyPage(); // Return the pages we've created. return new[] {page}; } } ``` -------------------------------- ### Show SharpShell Configuration Source: https://sharpshell.readthedocs.io/en/latest/srm/srm Displays the current SharpShell configuration stored in the registry. ```bash srm config ``` -------------------------------- ### Implement Search Button Click Handler Source: https://sharpshell.readthedocs.io/en/latest/extensions/deskband/deskband Handle the button click event to launch a Google search in the default browser. ```csharp private void buttonGo_Click(object sender, EventArgs e) { Process.Start("http://google.com#q=" + textBoxSearch.Text); } ``` -------------------------------- ### Define the DeskBand Server Class Source: https://sharpshell.readthedocs.io/en/latest/extensions/deskband/deskband Create a class inheriting from SharpDeskBand to define the UI and band configuration options. ```csharp [ComVisible(true)] [DisplayName("Web Search")] public class WebSearchDeskBand : SharpDeskBand { protected override System.Windows.Forms.UserControl CreateDeskBand() { return new DeskBandUI(); } protected override BandOptions GetBandOptions() { return new BandOptions { HasVariableHeight = false, IsSunken = false, ShowTitle = true, Title = "Web Search", UseBackgroundColour = false, AlwaysShowGripper = true }; } } ``` -------------------------------- ### Implement CreateMenu Override Source: https://sharpshell.readthedocs.io/en/latest/context-menu Constructs the ContextMenuStrip and adds menu items with event handlers. ```csharp protected override ContextMenuStrip CreateMenu() { // Create the menu strip. var menu = new ContextMenuStrip(); // Create an item. var itemCountLines = new ToolStripMenuItem { Text = "Do something ...", Image = Properties.Resources.CountLines }; // Add a handler for the click event. itemCountLines.Click += (sender, args) => MessageBox.Show("Do something"); // Add the item to the context menu. menu.Items.Add(itemCountLines); // Return the menu. return menu; } ``` -------------------------------- ### Create FileTimesPropertyPage Class Source: https://sharpshell.readthedocs.io/en/latest/extensions/propertysheetextension/propertysheetextension Implement the property page by inheriting from SharpPropertyPage. Override methods like OnPropertyPageInitialised, OnPropertySheetApply, and OnPropertySheetOK to handle page lifecycle and user interactions. ```csharp public partial class FileTimesPropertyPage : SharpPropertyPage { public FileTimesPropertyPage() { InitializeComponent(); // Set the page title. PageTitle = "File Times"; } protected override void OnPropertyPageInitialised(SharpPropertySheet parent) { // Store the file path. filePath = parent.SelectedItemPaths.First(); // Load the file times into the dialog. LoadFileTimes(); } protected override void OnPropertySheetApply() { // Save the changes. SaveFileTimes(); } protected override void OnPropertySheetOK() { // Save the changes. SaveFileTimes(); } private void LoadFileTimes() { // ... } private void SaveFileTimes() { // ... } private string filePath; } ``` -------------------------------- ### Associate COM Server with File Extension Class Source: https://sharpshell.readthedocs.io/en/latest/com-server-associations Registers a handler for a class of files by specifying an extension that resolves to a file type. ```csharp [COMServerAssociation(AssociationType.ClassOfExtension, ".dll")] public class DllIconHandler : SharpIconHandler ``` ```csharp // Associate the CustomIconHandler server with the class of jpg files. [COMServerAssociation(AssociationType.ClassOfExtension, ".jpg")] public class CustomIconHandler : SharpIconHandler ``` ```csharp // Associate the CustomIconHandler server with the class of jpg and png. [COMServerAssociation(AssociationType.ClassOfExtension, ".jpg", ".png")] public class CustomIconHandler : SharpIconHandler ``` -------------------------------- ### Showing SharpShell Config Source: https://sharpshell.readthedocs.io/en/latest/srm/srm Command to display the current SharpShell configuration stored in the registry. ```APIDOC ## Showing SharpShell Config SharpShell config is stored locally in the registry. It is only used for diagnostic purposes, typically SharpShell config will not be present unless diagnosing issues. Show current config with: ``` srm config ``` ``` -------------------------------- ### Setting SharpShell Config Source: https://sharpshell.readthedocs.io/en/latest/srm/srm Commands for setting SharpShell configuration values, including supported settings and their possible values. ```APIDOC ## Setting SharpShell Config Set SharpShell settings with the verb `config`: ``` srm config ``` The following settings are supported: | Setting | Value | |--------------|---------------------------------------------| | `LoggingMode`| Disabled, Debug, EventLog, File | | `LogPath` | _Any file path_ | These configuration settings are described in more detail in the Logging Documentation. Note that logging options will normally require a restart of the `explorer.exe` process to take effect. ``` -------------------------------- ### Associate COM Server with File Extensions (Deprecated) Source: https://sharpshell.readthedocs.io/en/latest/com-server-associations Registers a handler for specific file extensions. Note that this method is often not respected by Windows 7 and 8, which prefer class-based associations. ```csharp // Associate the CustomIconHandler server with batch files. [COMServerAssociation(AssociationType.FileExtension, ".bat")] public class CustomIconHandler : SharpIconHandler ``` ```csharp // Associate the CustomIconHandler server with jpeg files. [COMServerAssociation(AssociationType.FileExtension, ".jpg". ".jpeg")] public class CustomIconHandler : SharpIconHandler ``` -------------------------------- ### Uninstall SharpShell Servers Source: https://sharpshell.readthedocs.io/en/latest/srm/srm Command to remove a previously registered server DLL. ```bash srm uninstall ``` -------------------------------- ### Uninstall SharpShell Server using regasm Source: https://sharpshell.readthedocs.io/en/latest/installing/installing Uninstall a SharpShell server registered with regasm using the /u flag. ```bash regasm /u ExampleContextMenuExtension.dll ``` -------------------------------- ### Uninstall SharpShell Server using srm Source: https://sharpshell.readthedocs.io/en/latest/installing/installing Uninstall a SharpShell server using the srm uninstall command. ```bash srm uninstall ``` -------------------------------- ### Associate COM Server with Specific Class Source: https://sharpshell.readthedocs.io/en/latest/com-server-associations Registers a handler by directly specifying the programmatic identifier (ProgID) of the file class. ```csharp [COMServerAssociation(AssociationType.Class, "dllfile")] public class CustomIconHandler : SharpIconHandler ``` -------------------------------- ### Associate COM Server with Predefined Shell Objects Source: https://sharpshell.readthedocs.io/en/latest/com-server-associations Registers a handler for system-wide shell locations or object types using predefined association types. ```csharp [COMServerAssociation(AssociationType.AllFiles)] public class CustomIconHandler : SharpIconHandler ``` ```csharp [COMServerAssociation(AssociationType.Directory)] public class CustomIconHandler : SharpIconHandler ``` ```csharp [COMServerAssociation(AssociationType.DirectoryBackground)] public class CustomIconHandler : SharpIconHandler ``` ```csharp [COMServerAssociation(AssociationType.DesktopBackground)] public class CustomIconHandler : SharpIconHandler ``` ```csharp [COMServerAssociation(AssociationType.Drive)] public class CustomIconHandler : SharpIconHandler ``` ```csharp // Associate the CustomIconHandler server with the all unknown file types. [COMServerAssociation(AssociationType.UnknownFiles)] public class CustomIconHandler : SharpIconHandler ``` -------------------------------- ### Explicit Logging Calls in C# Source: https://sharpshell.readthedocs.io/en/latest/logging/logging Demonstrates how to explicitly log messages and errors using the Logging class. Ensure the Logging class is accessible in your scope. ```csharp Logging.Log("Message from SharpShell"); Logging.Error("Uh-oh", new Exception()); ``` -------------------------------- ### Configure Shortcut Keys Source: https://sharpshell.readthedocs.io/en/latest/context-menu ShortcutKeys must include a modifier key to be valid; otherwise, an InvalidEnumArgumentException will be thrown. ```csharp new ToolStripMenuItem { Text = "Count Lines...", Image = Properties.Resources.CountLines, ShortcutKeys = Keys.C }; ``` -------------------------------- ### Force Icon Overlay Handler Registration Order Source: https://sharpshell.readthedocs.io/en/latest/troubleshooting Use the 'RegistrationName' attribute with leading spaces to prioritize your icon overlay handler in the Windows Explorer list. This is useful when multiple handlers are registered. ```csharp [RegistrationName(" ReadOnlyFileIconOverlayHandler")] // push our way up the list by putting spaces in the name... public class ReadOnlyFileIconOverlayHandler : SharpIconOverlayHandler ``` -------------------------------- ### Set SharpShell Configuration Source: https://sharpshell.readthedocs.io/en/latest/srm/srm Updates specific SharpShell settings. Changes may require an explorer.exe restart. ```bash srm config ``` -------------------------------- ### Registry Key for Logging Configuration Source: https://sharpshell.readthedocs.io/en/latest/logging/logging This is the base registry key used to configure all SharpShell logging options. ```plaintext HKEY_LOCAL_MACHINE\Software\SharpShell ``` -------------------------------- ### Define Class with Public Constructor Source: https://sharpshell.readthedocs.io/en/latest/installing/installing Ensure the class has an implicit or explicit public default constructor for COM instantiation. ```csharp [ComVisible(true)] [COMServerAssociation(AssociationType.ClassOfExtension, ".txt")] public class CountLinesExtension : SharpContextMenu { // Good - this class has an implicit public constructor. } ``` ```csharp [ComVisible(true)] [COMServerAssociation(AssociationType.ClassOfExtension, ".txt")] public class CountLinesExtension : SharpContextMenu { protected CountLinesExtension() { // Bad - there is no public constructor. } } ``` -------------------------------- ### Define a Shell Context Menu Class Source: https://sharpshell.readthedocs.io/en/latest/context-menu The base class for a shell context menu must inherit from SharpContextMenu and include the ComVisible and COMServerAssociation attributes. ```csharp [ComVisible(true)] [COMServerAssociation(AssociationType.ClassOfExtension, ".txt")] public class ExampleShellExtension : SharpContextMenu { } ``` -------------------------------- ### Set Assembly COM Visibility Source: https://sharpshell.readthedocs.io/en/latest/installing/installing Configure the assembly-level attribute in AssemblyInfo.cs to make all types COM visible. ```csharp [assembly: ComVisible(true)] ``` -------------------------------- ### Define COM Visible Class Source: https://sharpshell.readthedocs.io/en/latest/installing/installing Apply the ComVisible attribute to the class to ensure it is visible to COM. ```csharp [ComVisible(true)] [COMServerAssociation(AssociationType.ClassOfExtension, ".txt")] public class CountLinesExtension : SharpContextMenu ``` ```csharp [COMServerAssociation(AssociationType.ClassOfExtension, ".txt")] public class CountLinesExtension : SharpContextMenu ``` -------------------------------- ### Implement CanShowMenu Override Source: https://sharpshell.readthedocs.io/en/latest/context-menu This method determines if the context menu should be displayed based on the selected items in SelectedItemPaths. ```csharp protected override bool CanShowMenu() { // Depending on the files in 'SelectedItemPaths' you might not show the menu. return true; } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.