fix(installer): drop the PowerShell association-notify action Defender blocks

#1080 ran a hidden PowerShell after install and uninstall that P/Invoked
shell32 SHChangeNotify(SHCNE_ASSOCCHANGED). Microsoft Defender flags that
pattern as a malicious command line and shows the user a security alert
(reported on v0.23.0). Remove the custom action; test-msi.ps1 now fails if
any custom action runs PowerShell.

Trade-off: Explorer's cached "Open with" list may miss PdfCraft until
sign-out after a fresh install, as before #1080.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Martin Ball
2026-11-30 09:59:20 +00:00
parent b928060f8e
commit 332544fa07
2 changed files with 9 additions and 21 deletions
-12
View File
@@ -74,7 +74,6 @@
</StandardDirectory>
<StandardDirectory Id="ProgramMenuFolder" />
<StandardDirectory Id="DesktopFolder" />
<StandardDirectory Id="SystemFolder" />
<Feature Id="Main" Title="PdfCraft" Level="1">
<?if $(var.HasCraftFontLicences) = 1 ?>
@@ -84,17 +83,6 @@
<ComponentGroupRef Id="PdfcraftModels" />
</Feature>
<!-- #1080: Windows Installer writes the PDF handler keys but never tells the shell, so Explorer's
cached "Open with" list misses PdfCraft until sign-out. Windows requires
SHChangeNotify(SHCNE_ASSOCCHANGED) after association changes; send it after install and
uninstall. Immediate (user's session, where Explorer runs); failure must not fail setup.
SystemFolder's PowerShell is always 32-bit (SysWOW64 on 64-bit Windows), so int fits the
pointer arguments. [\[] and [\]] escape [ and ]; Target is capped at 255 characters. -->
<CustomAction Id="NotifyAssociationsChanged" Directory="SystemFolder" Execute="immediate" Return="ignore"
ExeCommand="&quot;[SystemFolder]WindowsPowerShell\v1.0\powershell.exe&quot; -NoP -W Hidden -C (Add-Type -PassThru -Name N -MemberDefinition '[\[]DllImport(\&quot;shell32\&quot;)[\]]public static extern void SHChangeNotify(int e,int f,int a,int b);')::SHChangeNotify(0x8000000,0,0,0)" />
<InstallExecuteSequence>
<Custom Action="NotifyAssociationsChanged" After="InstallFinalize" />
</InstallExecuteSequence>
<Property Id="CRAFT_OPTION_1_M" Secure="yes"><RegistrySearch Id="CRAFT_OPTION_1_MSearch" Root="HKLM" Key="Software\Classes\SystemFileAssociations\.pdf\shell\PdfCraft.Edit" Type="raw" />
</Property><SetProperty Id="EXISTINGPDFCONTEXTMENU" Action="CraftLoadOption1M" Value="[CRAFT_OPTION_1_M]" After="LaunchConditions" Sequence="both" Condition="ALLUSERS = 1" /><Property Id="CRAFT_OPTION_1_U" Secure="yes"><RegistrySearch Id="CRAFT_OPTION_1_USearch" Root="HKCU" Key="Software\Classes\SystemFileAssociations\.pdf\shell\PdfCraft.Edit" Type="raw" />
</Property><SetProperty Id="EXISTINGPDFCONTEXTMENU" Action="CraftLoadOption1U" Value="[CRAFT_OPTION_1_U]" After="CraftLoadOption1M" Sequence="both" Condition="ALLUSERS &lt;&gt; 1" /><Property Id="CRAFT_OPTION_2_M" Secure="yes"><RegistrySearch Id="CRAFT_OPTION_2_MSearch" Root="HKLM" Key="Software\Classes\SystemFileAssociations\.png\shell\PdfCraft.CreatePdf" Type="raw" />
+9 -9
View File
@@ -249,15 +249,15 @@ if ($pdfCheckbox[2] -notmatch '&Edit' -or $pdfCheckbox[2] -notmatch 'Combine fil
$pdfChecked = Read-Row 'SELECT `Value` FROM `CheckBox` WHERE `Property` = ''INSTALLPDFCONTEXTMENU''' 1
Assert-Equal $pdfChecked[0] '1' 'Welcome PDF context-menu value'
Assert-NoRow 'SELECT `Registry` FROM `Registry` WHERE `Key` = ''Software\Classes\.pdf'' AND `Name` IS NULL' '.pdf default app'
# #1080: Explorer is told the associations changed (SHCNE_ASSOCCHANGED) after install/uninstall,
# without ever failing setup. 34 = exe in a directory; 64 = ignore its exit code.
$notify = Read-Row 'SELECT `Type`, `Source`, `Target` FROM `CustomAction` WHERE `Action` = ''NotifyAssociationsChanged''' 3
Assert-Equal $notify[0] '98' 'Association notify action type'
Assert-Equal $notify[1] 'SystemFolder' 'Association notify directory'
if ($notify[2] -notmatch 'SHChangeNotify\(0x8000000,0,0,0\)' -or $notify[2].Length -gt 255) { throw "Association notify command: '$($notify[2])'" }
$after = Read-Row 'SELECT `Sequence` FROM `InstallExecuteSequence` WHERE `Action` = ''NotifyAssociationsChanged''' 1
$finalize = Read-Row 'SELECT `Sequence` FROM `InstallExecuteSequence` WHERE `Action` = ''InstallFinalize''' 1
if ([int] $after[0] -le [int] $finalize[0]) { throw 'Association notify must run after InstallFinalize' }
# No custom action runs PowerShell: Defender blocks hidden PowerShell that P/Invokes shell32 as
# malicious (it did for #1080's SHChangeNotify action), and the user sees a security alert.
$actionView = $Database.OpenView('SELECT `Action`, `Target` FROM `CustomAction`')
try {
[void] $actionView.Execute()
while ($record = $actionView.Fetch()) {
if ($record.StringData(2) -like '*powershell*') { throw "custom action runs PowerShell: $($record.StringData(1))" }
}
} finally { [void] $actionView.Close() }
# "Combine files in PdfCraft" (#585): in the PDF menu's component, so the one switch covers both
# verbs. Each selected file starts `pdfcraft --combine "<file>"` (Document), and the running