NSIS调用卸载日志进行安全卸载
文章转自王牌软件
站长推荐:NSetup一键部署软件
一键式完成美化安装包制作,自动增量升级,数据统计,数字签名。应对各种复杂场景,脚本模块化拆分,常规复杂的脚本代码,图形化设置。无需专业的研发经验,轻松完成项目部署。(www.nsetup.cn)
只回答业务咨询
站长推荐:NSetup一键部署软件
一键式完成美化安装包制作,自动增量升级,数据统计,数字签名。应对各种复杂场景,脚本模块化拆分,常规复杂的脚本代码,图形化设置。无需专业的研发经验,轻松完成项目部署。(www.nsetup.cn)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
1、在普通安装脚本前添加库 !include "LogicLib.nsh" 2、; 激活安装日志记录,该日志文件将会作为卸载文件的依据(注意,本区段必须放置在所有区段之前) Section "-LogSetOn" LogSet on SectionEnd 3、 /****************************** * 以下是安装程序的卸载部分 * ******************************/ ; 根据安装日志卸载文件的调用宏 !macro DelFileByLog LogFile ifFileExists `${LogFile}` 0 +4 Push `${LogFile}` Call un.DelFileByLog Delete `${LogFile}` !macroend Section Uninstall !insertmacro MUI_STARTMENU_GETFOLDER "Application" $ICONS_GROUP Delete "$INSTDIR\${PRODUCT_NAME}.url" ; 调用宏只根据安装日志卸载安装程序自己安装过的文件 !insertmacro DelFileByLog "$INSTDIR\install.log" ; 清除安装程序创建的且在卸载时可能为空的子目录,对于递归添加的文件目录,请由最内层的子目录开始清除(注意,不要带 /r 参数,否则会失去 DelFileByLog 的意义) RMDir "$SMPROGRAMS\$ICONS_GROUP" SectionEnd #-- 根据 NSIS 脚本编辑规则,所有 Function 区段必须放置在 Section 区段之后编写,以避免安装程序出现未可预知的问题。--# ; 以下是卸载程序通过安装日志卸载文件的专用函数,请不要随意修改 Function un.DelFileByLog Exch $R0 Push $R1 Push $R2 Push $R3 FileOpen $R0 $R0 r ${Do} FileRead $R0 $R1 ${IfThen} $R1 == `` ${|} ${ExitDo} ${|} StrCpy $R1 $R1 -2 StrCpy $R2 $R1 11 StrCpy $R3 $R1 20 ${If} $R2 == "File: wrote" ${OrIf} $R2 == "File: skipp" ${OrIf} $R3 == "CreateShortCut: out:" ${OrIf} $R3 == "created uninstaller:" Push $R1 Push `"` Call un.DelFileByLog.StrLoc Pop $R2 ${If} $R2 != "" IntOp $R2 $R2 + 1 StrCpy $R3 $R1 "" $R2 Push $R3 Push `"` Call un.DelFileByLog.StrLoc Pop $R2 ${If} $R2 != "" StrCpy $R3 $R3 $R2 Delete /REBOOTOK $R3 ${EndIf} ${EndIf} ${EndIf} StrCpy $R2 $R1 7 ${If} $R2 == "Rename:" Push $R1 Push "->" Call un.DelFileByLog.StrLoc Pop $R2 ${If} $R2 != "" IntOp $R2 $R2 + 2 StrCpy $R3 $R1 "" $R2 Delete /REBOOTOK $R3 ${EndIf} ${EndIf} ${Loop} FileClose $R0 Pop $R3 Pop $R2 Pop $R1 Pop $R0 FunctionEnd Function un.DelFileByLog.StrLoc Exch $R0 Exch Exch $R1 Push $R2 Push $R3 Push $R4 Push $R5 StrLen $R2 $R0 StrLen $R3 $R1 StrCpy $R4 0 ${Do} StrCpy $R5 $R1 $R2 $R4 ${If} $R5 == $R0 ${OrIf} $R4 = $R3 ${ExitDo} ${EndIf} IntOp $R4 $R4 + 1 ${Loop} ${If} $R4 = $R3 StrCpy $R0 "" ${Else} StrCpy $R0 $R4 ${EndIf} Pop $R5 Pop $R4 Pop $R3 Pop $R2 Pop $R1 Exch $R0 FunctionEnd |
学习日记,兼职软件设计,软件修改,毕业设计。
本文出自 学习日记,转载时请注明出处及相应链接。
本文永久链接: https://www.softwareace.cn/?p=1238