2

I have written this simplistic shell extension (explorer context menu) with SharpShell:

[ComVisible(true)]
[COMServerAssociation(AssociationType.AllFiles)]
public class SampleExtension : SharpContextMenu
{
    protected override bool CanShowMenu()
    {
        return true;
    }
    protected override ContextMenuStrip CreateMenu()
    {
        var menu = new ContextMenuStrip();
        var item = new ToolStripMenuItem
        {
            Text = "Hello world!"
        };
        menu.Items.Add(item);
        return menu;
    }
}

It works fine when I deploy it manually.

Based on William's instructions, I wrote the WiX script below to install the shell extension on 32bit PCs:

<?xml version='1.0' encoding='windows-1252'?>
<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>

  <Product Name='Sample Extension' Id='PUT-GUID-HERE' 
            UpgradeCode='PUT-GUID-HERE' Language='1033' Codepage='1252'
            Version='0.1.23' Manufacturer='Me'>

    <Package Id='*' Keywords='Installer' Description="Sample Extension Setup"
             Manufacturer='Me' InstallerVersion='200' Languages='1033' 
             Compressed='yes' SummaryCodepage='1252' InstallScope='perMachine'
             Platform='x86'/>

    <Media Id='1' Cabinet='SampleExtension.cab' EmbedCab='yes' 
           DiskPrompt='Sample CAB' />
    <Property Id='DiskPrompt' 
              Value="SampleExtension Bundle CAB Installation" />

    <Directory Id='TARGETDIR' Name='SourceDir'>
      <Directory Id='ProgramFilesFolder' Name='PFiles'>
        <Directory Id='INSTALLDIR' Name='SampleExtension'>
          <Component Id='Libraries' Guid='*'>
            <File Id='SampleExtension.dll' Name='SampleExtension.dll'
                  Source='SampleExtension\bin\Debug\SampleExtension.dll' 
                  DiskId='1' />
            <File Id='SharpShell.dll' Name='SharpShell.dll' 
                  Source='SampleExtension\bin\Debug\SharpShell.dll' 
                  DiskId='1' />
            <File Id="SrmExe" Source="Extras\srm.exe"/>
          </Component>
        </Directory>
      </Directory>
    </Directory>

    <CustomAction Id="InstallShell" FileKey="SrmExe" 
          ExeCommand='install "[INSTALLFOLDER]\Application.dll" -codebase'
          Execute="deferred" Return="check" Impersonate="no" />
    <CustomAction Id="UninstallShell" FileKey="SrmExe" 
          ExeCommand='uninstall "[INSTALLFOLDER]\Application.dll"'
          Execute="deferred" Return="check" Impersonate="no" />
    <InstallExecuteSequence>
      <Custom Action="InstallShell" 
        After="InstallFiles">NOT Installed
      </Custom>
      <Custom Action="UninstallShell" 
        Before="RemoveFiles">(NOT UPGRADINGPRODUCTCODE) AND (REMOVE="ALL")
      </Custom>
    </InstallExecuteSequence>


    <Feature Id='SampleExtensionFeature' Title='Sample' Description='Sample' 
             Level='1' AllowAdvertise='no'>
      <ComponentRef Id="Libraries" />
    </Feature>

    <Property Id="MSIUSEREALADMINDETECTION" Value="1" />
    <Property Id="WIXUI_INSTALLDIR" Value="INSTALLDIR" />
    <WixVariable Id="WixUILicenseRtf" Value="license.rtf" />
    <UI><UIRef Id="WixUI_InstallDir" /></UI>
  </Product>
</Wix>

But after installing the MSI, the shell context menu does not appear. ShellExView does not even show it:

ShellExView SharpShell WiX

Here is the MSI log part that mentions srm, it is not really understandable for me:

Executing op: FileCopy(SourceName=srm.exe,SourceCabKey=SrmExe,DestName=srm.exe,Attributes=512,FileSize=151552,PerTick=65536,,VerifyMedia=1,,,,,CheckCRC=0,Version=2.1.0.0,Language=0,InstallMode=58982400,,,,,,,)
File: C:\Program Files\CmisSyncShellExtension\srm.exe;  To be installed;    Won't patch;    No existing file
Source for file 'SrmExe' is compressed
InstallFiles: File: srm.exe,  Directory: C:\Program Files\CmisSyncShellExtension\,  Size: 151552
Executing op: CacheSizeFlush(,)
Executing op: ActionStart(Name=InstallShell,,)
Action 18:30:13: InstallShell. 
Executing op: CustomActionSchedule(Action=InstallShell,ActionType=3090,Source=C:\Program Files\CmisSyncShellExtension\srm.exe,Target=install "\Application.dll" -codebase,)
Executing op: ActionStart(Name=RegisterProduct,Description=Registering product,Template=[1])
Action 18:30:13: RegisterProduct. Registering product
4

0 回答 0