需求:安裝包限制安裝次數。分兩種場景:
InstallUISequence 階段讀取註冊表 HKCU\Software\YourApp\InstallCount。>= 最大次數 → 彈窗提示並 Abort。InstallCount++ 寫回。缺點:用戶可手動刪除註冊表繞過。
/api/check?sn=xxx)。{allowed: true, count: 3},超限返回 {allowed: false}。/api/confirm 計數 +1。優點:防破解、可統計、支援授權管理。
InstallScript 或 Custom Action (DLL/VBScript/PowerShell) 實現邏輯。OnFirstUIBefore 或 SdWelcome 之後插入自定義對話框驗證。WinHttp 或 URLDownloadToFile 同步調用。Var InstallCount
Section
ReadRegStr $InstallCount HKCU "Software\MyApp" "InstallCount"
StrCmp $InstallCount "" 0 +2
StrCpy $InstallCount "0"
IntOp $InstallCount $InstallCount + 1
IntCmp $InstallCount 4 0 +2 +3 ; 超過3次
MessageBox MB_OK "安裝次數已達上限"
Abort
WriteRegStr HKCU "Software\MyApp" "InstallCount" "$InstallCount"
SectionEnd
根據業務場景選擇本地或雲端驗證方案。