### Install a SharpShell Server Source: https://github.com/dwmkerr/sharpshell/blob/main/SharpShell/Tools/ServerRegistrationManager/Actions/Help.txt Installs a SharpShell server. Use the -codebase parameter to install from a file location instead of the GAC. Use -os32 or -os64 to force a specific bitness. ```bash srm install ``` -------------------------------- ### Install SharpShell Server Source: https://github.com/dwmkerr/sharpshell/blob/main/docs/srm/srm.md Use this command to install a SharpShell server from a DLL. Ensure the DLL path is correct. ```bash srm install ``` -------------------------------- ### Install SharpShell Server with srm (GAC) Source: https://github.com/dwmkerr/sharpshell/blob/main/docs/installing/installing.md Install an assembly to the GAC and register it using the srm install command. ```bash gacutil -i srm install ``` -------------------------------- ### Install SharpShell Server with srm (Codebase) Source: https://github.com/dwmkerr/sharpshell/blob/main/docs/installing/installing.md Register a local assembly using the srm install command with the -codebase flag. ```bash srm install -codebase ``` -------------------------------- ### Install Octokit via NuGet Source: https://github.com/dwmkerr/sharpshell/blob/main/SharpShell/packages/Octokit.0.1.7/README.md Command to install the Octokit package using the NuGet Package Manager Console. ```powershell Install-Package Octokit ``` -------------------------------- ### Install SharpShell via NuGet Source: https://context7.com/dwmkerr/sharpshell/llms.txt Install SharpShell using the NuGet Package Manager Console or the .NET CLI. ```powershell # Install using NuGet Package Manager Console PM> Install-Package SharpShell ``` ```powershell # Or using .NET CLI dotnet add package SharpShell ``` -------------------------------- ### Install SharpShell Server with regasm (Codebase) Source: https://github.com/dwmkerr/sharpshell/blob/main/docs/installing/installing.md Register a local assembly as a COM server using the /codebase flag. ```bash regasm /codebase ExampleContextMenuExtension.dll ``` -------------------------------- ### Install SharpShell Server with regasm (GAC) Source: https://github.com/dwmkerr/sharpshell/blob/main/docs/installing/installing.md Register an assembly in the GAC and then register it as a COM server using regasm. ```bash gacutil -i ExampleContextMenuExtension.dll regasm ExampleContextMenuExtension.dll ``` -------------------------------- ### Install SharpShell Server with Specific Bitness Source: https://github.com/dwmkerr/sharpshell/blob/main/docs/srm/srm.md Installs a SharpShell server with a specified bitness (32-bit or 64-bit). The `-os32` or `-os64` flags control this. The `-codebase` flag is optional. ```bash srm install [-codebase] -os32 ``` ```bash srm install [-codebase] -os64 ``` -------------------------------- ### Get Help with SharpShell Source: https://github.com/dwmkerr/sharpshell/blob/main/SharpShell/Tools/ServerRegistrationManager/Actions/Help.txt Use this command to display help information for the SharpShell command-line tool. ```bash srm help ``` -------------------------------- ### Enable and Configure srm Logging Source: https://github.com/dwmkerr/sharpshell/blob/main/docs/installing/installing.md Configure srm to log installation activities to a file for troubleshooting purposes. ```bash srm config LoggingMode File srm config LogPath "%TEMP%\SharpShell.log" srm install srm config LoggingMode Disabled ``` -------------------------------- ### Install SharpShell Server without GAC Source: https://github.com/dwmkerr/sharpshell/blob/main/docs/srm/srm.md Installs a SharpShell server without registering it in the Global Assembly Cache (GAC). Use the `-codebase` flag for this purpose. ```bash srm install -codebase ``` -------------------------------- ### Manage Servers with srm.exe Source: https://context7.com/dwmkerr/sharpshell/llms.txt Use the SharpShell Server Registration Manager for simplified installation, configuration, and logging management. ```bash # Install a server (using GAC) gacutil -i MyExtension.dll srm install MyExtension.dll # Install without GAC srm install MyExtension.dll -codebase # Install with specific bitness srm install MyExtension.dll -codebase -os32 srm install MyExtension.dll -codebase -os64 # Uninstall a server srm uninstall MyExtension.dll # View current SharpShell configuration srm config # Configure logging mode (Disabled, Debug, EventLog, File) srm config LoggingMode File # Set log file path srm config LogPath "%TEMP%\SharpShell.log" # Enable logging, install, then disable srm config LoggingMode File srm config LogPath "%TEMP%\SharpShell.log" srm install MyExtension.dll -codebase srm config LoggingMode Disabled ``` -------------------------------- ### Install SharpShell via NuGet Source: https://github.com/dwmkerr/sharpshell/blob/main/docs/extensions/deskband/deskband.md Use the NuGet Package Manager console to add the SharpShell dependency to your project. ```powershell Install-Package SharpShell ``` -------------------------------- ### Register Servers with regasm Source: https://context7.com/dwmkerr/sharpshell/llms.txt Install or uninstall SharpShell servers using the standard .NET regasm tool, ensuring the correct bitness for the target OS. ```bash # Install using GAC (recommended for shared extensions) gacutil -i MyContextMenuExtension.dll regasm MyContextMenuExtension.dll # Install without GAC using codebase (files stay in place) regasm /codebase MyContextMenuExtension.dll # Uninstall a registered server regasm /u MyContextMenuExtension.dll # Use correct bitness for 64-bit Windows C:\Windows\Microsoft.NET\Framework64\v4.0.30319\regasm /codebase MyExtension.dll # Use correct bitness for 32-bit Windows C:\Windows\Microsoft.NET\Framework\v4.0.30319\regasm /codebase MyExtension.dll ``` -------------------------------- ### Install Chocolatey and Set Execution Policy Source: https://github.com/dwmkerr/sharpshell/blob/main/README.md This script is used to bypass the execution policy for the current process and install Chocolatey, a package manager for Windows. It ensures that the system can download and install necessary components for building. ```powershell Set-ExecutionPolicy Bypass -Scope Process -Force [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) ``` -------------------------------- ### Uninstall SharpShell Server Source: https://github.com/dwmkerr/sharpshell/blob/main/docs/srm/srm.md Use this command to uninstall a SharpShell server. Provide the path to the DLL that was installed. ```bash srm uninstall ``` -------------------------------- ### Example of Invalid Shortcut Key Source: https://github.com/dwmkerr/sharpshell/blob/main/docs/context-menu.md Demonstrates an invalid shortcut key assignment that will cause an exception. Shortcut keys must include a modifier (e.g., Keys.Alt | Keys.C). ```csharp new ToolStripMenuItem { Text = "Count Lines...", Image = Properties.Resources.CountLines, ShortcutKeys = Keys.C }; ``` -------------------------------- ### Clone and Build Octokit Locally Source: https://github.com/dwmkerr/sharpshell/blob/main/SharpShell/packages/Octokit.0.1.7/README.md Commands to clone the repository and execute the build script. ```bash git clone git@github.com:octokit/Octokit.net.git Octokit cd Octokit .\build.cmd ``` -------------------------------- ### Create a Custom Context Menu Extension Source: https://context7.com/dwmkerr/sharpshell/llms.txt Implement a custom right-click context menu for files using SharpContextMenu. Override CanShowMenu() to control visibility and CreateMenu() to define menu items. ```csharp using System.IO; using System.Runtime.InteropServices; using System.Text; using System.Windows.Forms; using SharpShell.Attributes; using SharpShell.SharpContextMenu; [ComVisible(true)] [COMServerAssociation(AssociationType.ClassOfExtension, ".txt")] public class CountLinesExtension : SharpContextMenu { // Determines whether the menu should be displayed protected override bool CanShowMenu() { // Show menu only when files are selected return SelectedItemPaths.Any(); } // Creates the context menu items protected override ContextMenuStrip CreateMenu() { var menu = new ContextMenuStrip(); var itemCountLines = new ToolStripMenuItem { Text = "Count Lines...", Image = Properties.Resources.CountLines }; // Handle the click event itemCountLines.Click += (sender, args) => CountLines(); menu.Items.Add(itemCountLines); return menu; } private void CountLines() { var builder = new StringBuilder(); foreach (var filePath in SelectedItemPaths) { var lineCount = File.ReadAllLines(filePath).Length; builder.AppendLine($"{Path.GetFileName(filePath)} - {lineCount} Lines"); } MessageBox.Show(builder.ToString()); } } ``` -------------------------------- ### Create Context Menu Items with CreateMenu Source: https://github.com/dwmkerr/sharpshell/blob/main/docs/context-menu.md Implement the CreateMenu method to build the actual context menu strip. This involves creating ToolStripItems, setting their properties like Text and Image, and defining click 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; } ``` -------------------------------- ### Register Server with Correct Bitness Source: https://github.com/dwmkerr/sharpshell/blob/main/docs/installing/installing.md Use the appropriate regasm path or srm flags based on the target operating 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 ``` -------------------------------- ### Define the DeskBand Server Class Source: https://github.com/dwmkerr/sharpshell/blob/main/docs/extensions/deskband/deskband.md Create a class inheriting from SharpDeskBand to define the UI and configuration options for the desk band. ```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 Web Search Button Handler Source: https://github.com/dwmkerr/sharpshell/blob/main/docs/extensions/deskband/deskband.md Handle the button click event to launch a browser with a Google search query. ```csharp private void buttonGo_Click(object sender, EventArgs e) { Process.Start("http://google.com#q=" + textBoxSearch.Text); } ``` -------------------------------- ### Implement a Custom Desk Band Source: https://context7.com/dwmkerr/sharpshell/llms.txt Create a custom taskbar band by inheriting from SharpDeskBand and overriding CreateDeskBand and GetBandOptions. ```csharp using System.Runtime.InteropServices; using System.Windows.Forms; using SharpShell.Attributes; using SharpShell.SharpDeskBand; [ComVisible(true)] [DisplayName("Web Search")] public class WebSearchDeskBand : SharpDeskBand { // Creates the desk band user interface protected override UserControl CreateDeskBand() { return new DeskBandUI(); } // Configures desk band options protected override BandOptions GetBandOptions() { return new BandOptions { HasVariableHeight = false, IsSunken = false, ShowTitle = true, Title = "Web Search", UseBackgroundColour = false, AlwaysShowGripper = true }; } } ``` -------------------------------- ### Define a Basic Shell Context Menu Class Source: https://github.com/dwmkerr/sharpshell/blob/main/docs/context-menu.md Implement a C# class that derives from SharpContextMenu. Ensure it's ComVisible and has a COMServerAssociation attribute to define which file types it applies to. ```csharp [ComVisible(true)] [COMServerAssociation(AssociationType.ClassOfExtension, ".txt")] public class ExampleShellExtension : SharpContextMenu { } ``` -------------------------------- ### Create Property Sheet Server Class Source: https://github.com/dwmkerr/sharpshell/blob/main/docs/extensions/propertysheetextension/propertysheetextension.md Define a class that derives from SharpPropertySheet to act as the main extension class. Associate it with shell objects using COMServerAssociation and make it visible as a COM server with ComVisible. ```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}; } } ``` -------------------------------- ### Implement Custom Folder InfoTip Handler Source: https://context7.com/dwmkerr/sharpshell/llms.txt Override GetInfo to provide custom tooltip information for folders. Handles different info types and single-line display. ```csharp using System; using System.IO; using System.Runtime.InteropServices; using SharpShell.Attributes; using SharpShell.SharpInfoTipHandler; [ComVisible(true)] [COMServerAssociation(AssociationType.Directory)] public class FolderInfoTipHandler : SharpInfoTipHandler { // Returns tooltip information for the selected item protected override string GetInfo(RequestedInfoType infoType, bool singleLine) { switch (infoType) { case RequestedInfoType.InfoTip: // Format folder info with file count var fileCount = Directory.GetFiles(SelectedItemPath).Length; return singleLine ? $"{Path.GetFileName(SelectedItemPath)} - {fileCount} Items" : $"{Path.GetFileName(SelectedItemPath)}{Environment.NewLine}Contains {fileCount} Items"; case RequestedInfoType.Name: return $"Folder '{Path.GetFileName(SelectedItemPath)}'"; default: return string.Empty; } } } ``` -------------------------------- ### View SharpShell Logging Mode Source: https://github.com/dwmkerr/sharpshell/wiki/Debugging-&-Diagnostics Use the 'srm' tool to display the current logging configuration for the machine. ```bash srm config ``` -------------------------------- ### Build SharpShellNativeBridge with PowerShell Source: https://github.com/dwmkerr/sharpshell/blob/main/SharpShellNativeBridge/README.md Use this script to build the SharpShellNativeBridge project. The CI/CD processes also utilize this script. ```powershell ./build.ps1 ``` -------------------------------- ### Implement Public Default Constructor Source: https://github.com/dwmkerr/sharpshell/blob/main/docs/installing/installing.md Ensure the server class provides a 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. } } ``` -------------------------------- ### Implement a File Preview Handler in C# Source: https://context7.com/dwmkerr/sharpshell/llms.txt Use SharpPreviewHandler to create a custom Windows Explorer preview pane. Requires a custom control inheriting from PreviewHandlerControl. ```csharp using System.Runtime.InteropServices; using System.Windows.Forms; using SharpShell.Attributes; using SharpShell.SharpPreviewHandler; [ComVisible(true)] [COMServerAssociation(AssociationType.ClassOfExtension, ".ico")] [DisplayName("Icon Preview Handler")] [Guid("B643C50D-4206-4121-A895-9EA5C919557A")] [PreviewHandler(DisableLowILProcessIsolation = false)] public class IconPreviewHandler : SharpPreviewHandler { // Creates and returns the preview control protected override PreviewHandlerControl DoPreview() { var handler = new IconPreviewHandlerControl(); // SelectedFilePath contains the path to the file being previewed if (!string.IsNullOrEmpty(SelectedFilePath)) handler.DoPreview(SelectedFilePath); return handler; } } // Custom preview control inheriting from PreviewHandlerControl public class IconPreviewHandlerControl : PreviewHandlerControl { public void DoPreview(string filePath) { // Load and display icons from the .ico file var pictureBox = new PictureBox { Image = new Icon(filePath).ToBitmap(), SizeMode = PictureBoxSizeMode.CenterImage, Dock = DockStyle.Fill }; Controls.Add(pictureBox); } } ``` -------------------------------- ### Implement Property Page Class Source: https://github.com/dwmkerr/sharpshell/blob/main/docs/extensions/propertysheetextension/propertysheetextension.md Create a UserControl that inherits from SharpPropertyPage to define a custom property page. Implement methods to handle initialization, apply, and OK events. Use SetPageDataChanged to enable the 'Apply' button. ```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; } ``` -------------------------------- ### Uninstall SharpShell Server with regasm Source: https://github.com/dwmkerr/sharpshell/blob/main/docs/installing/installing.md Unregister a previously registered COM server. ```bash regasm /u ExampleContextMenuExtension.dll ``` -------------------------------- ### Configure SharpShell Logging Mode via SRM Tool Source: https://github.com/dwmkerr/sharpshell/wiki/Debugging-&-Diagnostics Use the 'srm' command-line tool to configure logging. This is a convenient alternative to manual registry edits. ```bash srm config LoggingMode Debug ``` ```bash srm config LoggingMode "EventLog, File" ``` -------------------------------- ### Configure Registry Logging Source: https://github.com/dwmkerr/sharpshell/blob/main/docs/logging/logging.md Registry path for controlling SharpShell logging behavior. ```text HKEY_LOCAL_MACHINE\Software\SharpShell ``` -------------------------------- ### Associate COM Server with File Extension Class Source: https://github.com/dwmkerr/sharpshell/blob/main/docs/com-server-associations.md Registers a handler for a specific file extension class, which covers all extensions mapped to that 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 ``` -------------------------------- ### Associate Server with Unknown Files in C# Source: https://github.com/dwmkerr/sharpshell/blob/main/docs/com-server-associations.md Use the COMServerAssociation attribute with AssociationType.UnknownFiles to register a handler for all unknown file types. ```csharp // Associate the CustomIconHandler server with the all unknown file types. [COMServerAssociation(AssociationType.UnknownFiles)] public class CustomIconHandler : SharpIconHandler ``` -------------------------------- ### Associate COM Server with Specific Class Source: https://github.com/dwmkerr/sharpshell/blob/main/docs/com-server-associations.md Registers a handler using a known registry class name. ```csharp [COMServerAssociation(AssociationType.Class, "dllfile")] public class CustomIconHandler : SharpIconHandler ``` -------------------------------- ### Implement an Icon Overlay Handler in C# Source: https://context7.com/dwmkerr/sharpshell/llms.txt Inherit from SharpIconOverlayHandler to display custom status icons on files. Override CanShowOverlay to define logic for when the icon appears. ```csharp using System; using System.Drawing; using System.IO; using System.Runtime.InteropServices; using SharpShell.Attributes; using SharpShell.Interop; using SharpShell.SharpIconOverlayHandler; [ComVisible(true)] [RegistrationName(" ReadOnlyFileIconOverlayHandler")] // Spaces push priority up public class ReadOnlyFileIconOverlayHandler : SharpIconOverlayHandler { // Returns overlay priority (0-100, lower = higher priority) protected override int GetPriority() { return 90; // Low priority } // Determines if overlay should be shown for this item protected override bool CanShowOverlay(string path, FILE_ATTRIBUTE attributes) { try { var fileInfo = new FileInfo(path); return fileInfo.IsReadOnly; } catch (Exception) { return false; } } // Returns the overlay icon protected override Icon GetOverlayIcon() { return Properties.Resources.ReadOnly; } } ``` -------------------------------- ### Force Icon Overlay Handler Registration Order Source: https://github.com/dwmkerr/sharpshell/blob/main/docs/troubleshooting.md Use the 'RegistrationName' attribute to influence the order of icon overlay handlers. Prepending spaces can push your handler higher in the registration list, potentially ensuring it is displayed. ```csharp [RegistrationName(" ReadOnlyFileIconOverlayHandler")] // push our way up the list by putting spaces in the name... public class ReadOnlyFileIconOverlayHandler : SharpIconOverlayHandler ``` -------------------------------- ### Fetch User Information with Octokit Source: https://github.com/dwmkerr/sharpshell/blob/main/SharpShell/packages/Octokit.0.1.7/README.md Retrieves public information for a specific GitHub user using the GitHubClient. ```c# var github = new GitHubClient(new ProductHeaderValue("MyAmazingApp")); var user = await github.User.Get("half-ogre"); Console.WriteLine(user.Followers + " folks love the half ogre!"); ``` -------------------------------- ### Uninstall SharpShell Server with srm Source: https://github.com/dwmkerr/sharpshell/blob/main/docs/installing/installing.md Unregister a server using the srm uninstall command. ```bash srm uninstall ``` -------------------------------- ### Configure SharpShell Log File Path via SRM Tool Source: https://github.com/dwmkerr/sharpshell/wiki/Debugging-&-Diagnostics Specify the location for file logging using the 'srm' tool. Environment variables like %TEMP% are supported. ```bash srm config LogPath "%TEMP%\SharpShell.log" ``` -------------------------------- ### Implement a Custom Thumbnail Handler in C# Source: https://context7.com/dwmkerr/sharpshell/llms.txt Inherit from SharpThumbnailHandler and override GetThumbnailImage to generate bitmap previews for specific file extensions. ```csharp using System; using System.Collections.Generic; using System.Drawing; using System.IO; using System.Runtime.InteropServices; using SharpShell.Attributes; using SharpShell.SharpThumbnailHandler; [ComVisible(true)] [COMServerAssociation(AssociationType.ClassOfExtension, ".txt")] public class TxtThumbnailHandler : SharpThumbnailHandler { // Generates a thumbnail image for the file protected override Bitmap GetThumbnailImage(uint width) { Log($"Creating thumbnail for '{SelectedItemStream.Name}'"); try { using (var reader = new StreamReader(SelectedItemStream)) { // Read first 10 lines for preview var previewLines = new List(); for (int i = 0; i < 10; i++) { var line = reader.ReadLine(); if (line == null) break; previewLines.Add(line); } // Create thumbnail bitmap with text preview var bitmap = new Bitmap((int)width, (int)width); using (var graphics = Graphics.FromImage(bitmap)) { graphics.Clear(Color.White); var font = new Font("Consolas", 8); float y = 5; foreach (var line in previewLines) { graphics.DrawString(line, font, Brushes.Black, 5, y); y += 12; } } return bitmap; } } catch (Exception exception) { LogError("Failed to create thumbnail.", exception); return null; } } } ``` -------------------------------- ### Log Messages and Errors with SharpShell API Source: https://github.com/dwmkerr/sharpshell/wiki/Debugging-&-Diagnostics Use these static methods for general logging. Ensure SharpShell is referenced in your project. ```csharp Logging.Log("This is a message."); Logging.Error("This is an error."); Logging.Error("This is an error with exception details.", someException); ``` -------------------------------- ### Uninstall a SharpShell Server Source: https://github.com/dwmkerr/sharpshell/blob/main/SharpShell/Tools/ServerRegistrationManager/Actions/Help.txt Uninstalls a SharpShell server from the system. ```bash srm uninstall ``` -------------------------------- ### Associate COM Server with File Extensions Source: https://github.com/dwmkerr/sharpshell/blob/main/docs/com-server-associations.md Registers a handler for specific file extensions. Note that this approach is deprecated and may not be respected on newer Windows versions. ```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 ``` -------------------------------- ### Associate COM Server with Predefined Shell Objects Source: https://github.com/dwmkerr/sharpshell/blob/main/docs/com-server-associations.md Registers a handler for system-wide shell objects like directories, background contexts, or drives. ```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 ``` -------------------------------- ### Create a Custom File Icon Handler Source: https://context7.com/dwmkerr/sharpshell/llms.txt Customize file icons displayed in Windows Explorer using SharpIconHandler. Override GetIcon() to return the appropriate icon based on file properties. ```csharp using System; using System.Drawing; using System.Reflection; using System.Runtime.InteropServices; using SharpShell.Attributes; using SharpShell.SharpIconHandler; [ComVisible(true)] [COMServerAssociation(AssociationType.ClassOfExtension, ".dll")] public class DllIconHandler : SharpIconHandler { // Returns the icon for the selected file protected override Icon GetIcon(bool smallIcon, uint iconSize) { Icon icon = null; // Check if DLL is managed or native try { // SelectedItemPath contains the path of the current file AssemblyName.GetAssemblyName(SelectedItemPath); // No exception means it's a managed assembly icon = Properties.Resources.ManagedDll; } catch (BadImageFormatException) { // Native DLL icon = Properties.Resources.NativeDll; } catch (Exception) { icon = Properties.Resources.NativeDll; } // Return icon at the requested size return GetIconSpecificSize(icon, new Size((int)iconSize, (int)iconSize)); } } ``` -------------------------------- ### Registry Configuration for SharpShell Logging Source: https://context7.com/dwmkerr/sharpshell/llms.txt Configure SharpShell logging levels and file paths using the Windows registry. Values are DWORD for `LoggingMode` and String for `LogPath`. Multiple `LoggingMode` values can be combined by addition. ```bash # Enable debug output (view with DebugView from SysInternals) # Registry: HKLM\Software\SharpShell\LoggingMode = 1 (DWORD) # Enable file logging # Registry: HKLM\Software\SharpShell\LoggingMode = 4 (DWORD) # Registry: HKLM\Software\SharpShell\LogPath = "C:\\Logs\\SharpShell.log" (String) # Enable both debug and file logging # Registry: HKLM\Software\SharpShell\LoggingMode = 5 (DWORD) (1 + 4) ``` -------------------------------- ### Define COM Visible Server Class Source: https://github.com/dwmkerr/sharpshell/blob/main/docs/installing/installing.md Apply the ComVisible attribute to the server class to ensure it is discoverable by COM. ```csharp [ComVisible(true)] [COMServerAssociation(AssociationType.ClassOfExtension, ".txt")] public class CountLinesExtension : SharpContextMenu ``` ```csharp [COMServerAssociation(AssociationType.ClassOfExtension, ".txt")] public class CountLinesExtension : SharpContextMenu ``` -------------------------------- ### Implement Custom FileTimes Property Sheet Source: https://context7.com/dwmkerr/sharpshell/llms.txt Adds a custom property sheet page to display and modify file creation, modification, and access times. ```csharp using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.InteropServices; using System.Windows.Forms; using SharpShell.Attributes; using SharpShell.SharpPropertySheet; [ComVisible(true)] [COMServerAssociation(AssociationType.AllFiles)] public class FileTimesPropertySheet : SharpPropertySheet { // Determines if property pages should be shown protected override bool CanShowSheet() { return SelectedItemPaths.Count() == 1; } // Creates property pages to add to the property sheet protected override IEnumerable CreatePages() { return new[] { new FileTimesPropertyPage() }; } } // Property page implementation public class FileTimesPropertyPage : SharpPropertyPage { private string filePath; public FileTimesPropertyPage() { InitializeComponent(); PageTitle = "File Times"; } // Called when page is initialized with parent data protected override void OnPropertyPageInitialised(SharpPropertySheet parent) { filePath = parent.SelectedItemPaths.First(); LoadFileTimes(); } // Called when Apply button is clicked protected override void OnPropertySheetApply() { SaveFileTimes(); } // Called when OK button is clicked protected override void OnPropertySheetOK() { SaveFileTimes(); } private void LoadFileTimes() { var fileInfo = new FileInfo(filePath); // Load creation, modified, accessed times into UI controls } private void SaveFileTimes() { // Save modified times back to file } } ``` -------------------------------- ### Implement Custom XSD Drop Handler Source: https://context7.com/dwmkerr/sharpshell/llms.txt Handle files dropped onto .xsd files. Validates that dropped files are XML and displays a validation form. ```csharp using System; using System.IO; using System.Linq; using System.Runtime.InteropServices; using System.Windows.Forms; using SharpShell.Attributes; using SharpShell.SharpDropHandler; [ComVisible(true)] [COMServerAssociation(AssociationType.ClassOfExtension, ".xsd")] public class XsdDropHandler : SharpDropHandler { // Validates drag operation - called when files are dragged over target protected override void DragEnter(DragEventArgs dragEventArgs) { // Only accept XML files being dropped onto XSD files var allXml = DragItems.All(item => string.Equals(Path.GetExtension(item), ".xml", StringComparison.InvariantCultureIgnoreCase)); dragEventArgs.Effect = allXml ? DragDropEffects.Link : DragDropEffects.None; } // Handles the drop operation protected override void Drop(DragEventArgs dragEventArgs) { // SelectedItemPath = the XSD file being dropped onto // DragItems = the XML files being dropped var form = new ValidationOutputForm { XsdFilePath = SelectedItemPath, XmlFilePaths = DragItems }; form.ShowDialog(); } } ``` -------------------------------- ### Log Messages and Errors within SharpShellServer Class Source: https://github.com/dwmkerr/sharpshell/wiki/Debugging-&-Diagnostics When inside a class derived from `SharpShellServer`, use these methods for logging. The server's name is automatically included in log entries. ```csharp Log("This is a message."); LogError("This is an error."); LogError("This is an error with exception details.", someException); ``` -------------------------------- ### Programmatic Logging in SharpShell Extensions Source: https://context7.com/dwmkerr/sharpshell/llms.txt Use the `Log` and `LogError` methods within your SharpShell extension code to log informational messages and exceptions. Ensure the `SharpShell.Diagnostics` namespace is imported. ```csharp // Registry configuration (HKEY_LOCAL_MACHINE\Software\SharpShell) // LoggingMode (DWORD): 1=Debug, 2=EventLog, 4=File (can combine) // LogPath (String): File path for log output // Programmatic logging in server code using SharpShell.Diagnostics; public class MyExtension : SharpContextMenu { protected override ContextMenuStrip CreateMenu() { // Log informational messages Log("Creating context menu for selected files"); // Log with formatted string Log($"Processing {SelectedItemPaths.Count()} files"); try { // Extension logic here } catch (Exception ex) { // Log errors with exception details LogError("Failed to create menu", ex); } return menu; } } ``` -------------------------------- ### Set SharpShell Configuration Source: https://github.com/dwmkerr/sharpshell/blob/main/docs/srm/srm.md Sets a specific SharpShell configuration setting. The `LoggingMode` and `LogPath` are supported settings. Changes may require restarting `explorer.exe`. ```bash srm config ``` -------------------------------- ### Set Assembly COM Visibility Source: https://github.com/dwmkerr/sharpshell/blob/main/docs/installing/installing.md Configure the assembly-level attribute to make all types within the assembly COM visible. ```csharp [assembly: ComVisible(true)] ``` -------------------------------- ### Log Messages Programmatically Source: https://github.com/dwmkerr/sharpshell/blob/main/docs/logging/logging.md Explicitly write messages or errors to the log using the Logging class. ```csharp Logging.Log("Message from SharpShell"); Logging.Error("Uh-oh", new Exception()); ``` -------------------------------- ### Define COMServerAssociation Attributes Source: https://context7.com/dwmkerr/sharpshell/llms.txt Use the COMServerAssociation attribute to link shell extensions to specific file types, classes, or system locations. ```csharp using System.Runtime.InteropServices; using SharpShell.Attributes; using SharpShell.SharpIconHandler; // Associate with a specific file extension class (recommended) [ComVisible(true)] [COMServerAssociation(AssociationType.ClassOfExtension, ".jpg")] public class JpegIconHandler : SharpIconHandler { /* ... */ } // Associate with multiple file extension classes [ComVisible(true)] [COMServerAssociation(AssociationType.ClassOfExtension, ".jpg", ".png", ".gif")] public class ImageIconHandler : SharpIconHandler { /* ... */ } // Associate with a specific class name [ComVisible(true)] [COMServerAssociation(AssociationType.Class, "dllfile")] public class DllFileHandler : SharpIconHandler { /* ... */ } // Associate with all files [ComVisible(true)] [COMServerAssociation(AssociationType.AllFiles)] public class AllFilesHandler : SharpIconHandler { /* ... */ } // Associate with directories (folders) [ComVisible(true)] [COMServerAssociation(AssociationType.Directory)] public class FolderHandler : SharpContextMenu { /* ... */ } // Associate with directory background (right-click on empty space) [ComVisible(true)] [COMServerAssociation(AssociationType.DirectoryBackground)] public class DirectoryBackgroundHandler : SharpContextMenu { /* ... */ } // Associate with desktop background [ComVisible(true)] [COMServerAssociation(AssociationType.DesktopBackground)] public class DesktopBackgroundHandler : SharpContextMenu { /* ... */ } // Associate with drives [ComVisible(true)] [COMServerAssociation(AssociationType.Drive)] public class DriveHandler : SharpContextMenu { /* ... */ } // Associate with unknown file types [ComVisible(true)] [COMServerAssociation(AssociationType.UnknownFiles)] public class UnknownFilesHandler : SharpIconHandler { /* ... */ } ``` -------------------------------- ### Determine Menu Visibility with CanShowMenu Source: https://github.com/dwmkerr/sharpshell/blob/main/docs/context-menu.md Override the CanShowMenu method to control whether the context menu should appear for the selected items. The SelectedItemPaths property contains the paths of the selected items. ```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.