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

Troubleshooting installation issue with CountLinesExtension sample #382

Open
thexeos opened this issue Nov 30, 2022 · 4 comments
Open

Troubleshooting installation issue with CountLinesExtension sample #382

thexeos opened this issue Nov 30, 2022 · 4 comments

Comments

@thexeos
Copy link

thexeos commented Nov 30, 2022

Version of SharpShell used: 2.7.2

Related type(s) of SharpShell-Server: Any

Windows version: 10.0.19045 Build 19045

I am trying to install CountLinesExtension sample from here https://github.com/dwmkerr/sharpshell/tree/main/SharpShell/Samples/ContextMenu/CountLinesExtension using the ServerRegistrationManager (srm) tool. You can see the log below, but it basically works every time.

I also tried calling individual commands. Running gacutil -l "CountLinesExtension" afterwards finds the assembly in cache.

Furthermore, I tried swapping out the COMServerAssociation(AssociationType.ClassOfExtension, ".txt") for COMServerAssociation(AssociationType.AllFilesAndFolders) and registering that. Still no luck.

These were tried with both Release and Debug builds.

I see Explorer reload (quick flash of all icons) a second after running the srm install command (the srm uninstall does not trigger a visible flash). But none of the text files, or any files at all in the case of AllFilesAndFolders, get the new context menu item.

Are there any other logs I can look at or could I be doing something wrong?

(CCleaner shows available Context Menu extensions and this newly registered extension does not appear in the list, if that is of any help)

Log Messages

2022-11-30 07:19:20.897Z - ServerRegistrationManager - SharpShell Diagnostics Initialised. Process ServerRegistrationManager.
2022-11-30 07:19:20.906Z - ServerRegistrationManager - Started the Server Registration Manager.
2022-11-30 07:19:20.916Z - ServerRegistrationManager - RegAsm: preparing to run C:\Windows\Microsoft.Net\Framework64\v4.0.30319\regasm.exe ".\CountLinesExtension.dll"
2022-11-30 07:19:20.992Z - RegAsm - SharpShell Diagnostics Initialised. Process RegAsm.
2022-11-30 07:19:20.999Z - RegAsm - Registering server for type CountLinesExtension
2022-11-30 07:19:21.006Z - RegAsm - Preparing to register SharpShell Server CountLinesExtension as OS64Bit
2022-11-30 07:19:21.018Z - RegAsm - Registration of CountLinesExtension completed
2022-11-30 07:19:21.030Z - ServerRegistrationManager - RegAsm: exited with code 0
2022-11-30 07:19:21.036Z - ServerRegistrationManager - RegAsm: Output: Microsoft .NET Framework Assembly Registration Utility version 4.8.4084.0
for Microsoft .NET Framework version 4.8.4084.0
Copyright (C) Microsoft Corporation. All rights reserved.

Types registered successfully

2022-11-30 07:19:21.042Z - ServerRegistrationManager - .\CountLinesExtension.dll installed and registered.

@tomuxmon
Copy link

I have been scratching my head with this one also. I would guess there is still no support for Windows 11. Check issue 364. I hope it helps.

@BoutemineOualid
Copy link

I am currently using the System.Runtime.InteropServices.RegistrationServices class to automate the installation from the installer/debug project without any issues.

private readonly RegistrationServices _registrationServices = new();
// Registration
if (!_registrationServices.RegisterAssembly(GetType().Assembly, AssemblyRegistrationFlags.SetCodeBase))
{
       throw new InstallException("Failed to register the extensions.");
}

// Unregister
if (!_registrationServices.UnregisterAssembly(GetType().Assembly))
{
    throw new InstallException("Failed to unregister the extensions.");
}

This code can be executed from another assembly like a Console App referencing the extensions dll or directly through a System.Configuration.Install.Installer class within the extensions assembly that could be used as a Custom action from the visual studio installer project.

I personally never used the srm tool because the RegistrationServices class takes care of this.

@ecimen81
Copy link

private readonly RegistrationServices _registrationServices = new();
// Registration
if (!_registrationServices.RegisterAssembly(GetType().Assembly, AssemblyRegistrationFlags.SetCodeBase))
{
throw new InstallException("Failed to register the extensions.");
}

// Unregister
if (!_registrationServices.UnregisterAssembly(GetType().Assembly))
{
throw new InstallException("Failed to unregister the extensions.");
}

i am having trouble with registering dll for Windows 11 and i have tried your suggestion to get it work but had no luck

here my code

        Assembly asm = Assembly.LoadFile("CountLinesExtension.dll");
        // Registration
        if (!_registrationServices.RegisterAssembly(asm, AssemblyRegistrationFlags.SetCodeBase))

{
throw new InstallException("Failed to register the extensions.");
}

// Unregister
if (!_registrationServices.UnregisterAssembly(asm))
{
throw new InstallException("Failed to unregister the extensions.");
}
}

can you please guide me where i am doing at mistake?

@BoutemineOualid
Copy link

BoutemineOualid commented May 14, 2023

Here is a full working example


    [RunInstaller(true)]
    public partial class RegAsmInstaller : Installer
    {
        private readonly RegistrationServices _registrationServices;

        public RegAsmInstaller()
        {
            InitializeComponent();
            _registrationServices = new RegistrationServices();
        }

        [SecurityPermission(SecurityAction.Demand)]
        public override void Install(IDictionary stateSaver)
        {
            base.Install(stateSaver);

            if (!_registrationServices.RegisterAssembly(GetType().Assembly, AssemblyRegistrationFlags.SetCodeBase))
            {
                throw new InstallException("Failed to register shell extensions.");
            }

            RefreshExplorer();
        }

        [SecurityPermission(SecurityAction.Demand)]
        public override void Commit(IDictionary savedState)
        {
            base.Commit(savedState);

            if (!_registrationServices.RegisterAssembly(GetType().Assembly, AssemblyRegistrationFlags.SetCodeBase))
            {
                throw new InstallException("Failed to register shell extensions.");
            }

            RefreshExplorer();
        }

        [SecurityPermission(SecurityAction.Demand)]
        public override void Rollback(IDictionary savedState)
        {
            base.Rollback(savedState);

            if (!_registrationServices.UnregisterAssembly(GetType().Assembly))
            {
                throw new InstallException("Failed to unregister shell extensions.");
            }

            RefreshExplorer();
        }

        [SecurityPermission(SecurityAction.Demand)]
        public override void Uninstall(IDictionary savedState)
        {
            base.Uninstall(savedState);

            if (!_registrationServices.UnregisterAssembly(GetType().Assembly))
            {
                throw new InstallException("Failed to unregister shell extensions.");
            }

            RefreshExplorer();
        }

        public void RefreshExplorer()
        {
            try
            {
                PInvoke.SHLoadNonloadedIconOverlayIdentifiers();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not refresh Windows Explorer" + Environment.NewLine + ex.Message);
            }
        }
    }

    class PInvoke()
    {
        [DllImport("shell32.dll")]
        public static extern bool SHLoadNonloadedIconOverlayIdentifiers();
    }

Now in your VS Installer Project, you need to reference the dll containing this installer class in your Custom Actions screen. Right click on the installer project, View Custom Actions the right Click on Install and Select Add Custom Action, the select Application Folder.
image

The SourcePath should reference the output
image

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

4 participants