关于office2003后续补丁跳过已安装补丁的解决方法
优质
小牛编辑
138浏览
2023-12-01
通过检测打补丁要替换文件的版本来实现跳过已安装补丁,在nsis,也就是要用到GetFileVersion这个函数来实现:
!include "LogicLib.nsh" ; 安装程序初始定义常量 !define PRODUCT_NAME "office 2003 sp3后续补丁集" !define PRODUCT_VERSION "1.0" !define PRODUCT_PUBLISHER "Flan, Inc." SetCompressor lzma ; ------ MUI 现代界面定义 (1.67 版本以上兼容) ------ !include "MUI.nsh" !define MUI_WELCOMEFINISHPAGE_BITMAP "侧边栏.bmp" !define MUI_HEADERIMAGE_BITMAP "右上角.bmp" !define MUI_HEADERIMAGE !define MUI_HEADERIMAGE_RIGHT !define MUI_COMPONENTSPAGE_SMALLDESC ; MUI 预定义常量 !define MUI_ABORTWARNING !define MUI_ICON "setup.ico" ;!define MUI_UNICON "unistall.ico" ;注册表判断组件(自已定义的) !define MUI_PAGE_CUSTOMFUNCTION_Pre ComponentsPre ; 欢迎页面 !insertmacro MUI_PAGE_WELCOME ; 许可协议页面 !define MUI_LICENSEPAGE_CHECKBOX !insertmacro MUI_PAGE_LICENSE "xp.txt" !include "FileFunc.nsh" !insertmacro GetFileVersion ; 组件选择页面 !insertmacro MUI_PAGE_COMPONENTS ; 安装目录选择页面 !insertmacro MUI_PAGE_DIRECTORY ; 安装过程页面 !insertmacro MUI_PAGE_INSTFILES ; 安装完成页面 !insertmacro MUI_PAGE_FINISH ; 安装卸载过程页面 ;!insertmacro MUI_UNPAGE_INSTFILES ; 安装界面包含的语言设置 !insertmacro MUI_LANGUAGE "SimpChinese" ; 安装预释放文件 !insertmacro MUI_RESERVEFILE_INSTALLOPTIONS ; ------ MUI 现代界面定义结束 ------ Name "${PRODUCT_NAME} ${PRODUCT_VERSION}" OutFile "officepatch.exe" InstallDir "$TEMP" ShowInstDetails show InstType "自动检测安装" SectionGroup /e "Office 2003 sp3后续补丁" Section "Office 2003安全更新程序(KB959995)" SECof1 SectionIn 1 SetOutPath "$TEMP" File "pat\office2003-KB959995-FullFile-CHS.exe" ExecWait '"$TEMP\office2003-KB959995-FullFile-CHS.exe" /Q' SectionEnd Section "Office 2003安全更新程序(KB953404)" SECof2 SectionIn 1 SetOutPath "$TEMP" File "pat\office2003-KB953404-FullFile-CHS.exe" ExecWait '"$TEMP\office2003-KB953404-FullFile-CHS.exe" /Q' SectionEnd Section "Office 2003安全更新程序(KB954478)" SECof3 SectionIn 1 SetOutPath "$TEMP" File "pat\office2003-KB954478-FullFile-CHS.exe" ExecWait '"$TEMP\office2003-KB954478-FullFile-CHS.exe" /Q' SectionEnd Section "Office 2003安全更新程序(KB956357)" SECof4 SectionIn 1 SetOutPath "$TEMP" File "pat\office2003-KB956357-FullFile-CHS.exe" ExecWait '"$TEMP\office2003-KB956357-FullFile-CHS.exe" /Q' SectionEnd Section "Office 2003安全更新程序(KB948988)" SECof5 SectionIn 1 SetOutPath "$TEMP" File "pat\office2003-KB948988-FullFile-CHS.exe" ExecWait '"$TEMP\office2003-KB948988-FullFile-CHS.exe" /Q' SectionEnd SectionGroupEnd Function ComponentsPre ;下面为Office 2003 Sp3更新补丁判断,如果已经安装就不勾选相应补丁 ${GetFileVersion} "$PROGRAMFILES\Microsoft Office\OFFICE11\EXCEL.EXE" $0 ${If} $0 >= '11.0.8302.0' SectionSetFlags ${secof1} 16 ${Else} StrCmp $0 0 0 +1 ${EndIf} ${GetFileVersion} "$COMMONFILES\Microsoft Shared\OFFICE11\MSO.dll" $0 ${If} $0 >= '11.0.8221.0' SectionSetFlags ${secof2} 16 ${Else} StrCmp $0 0 0 +1 ${EndIf} ${GetFileVersion} "$PROGRAMFILES\Microsoft Office\OFFICE11\GDIPLUS.DLL" $0 ${If} $0 >= '11.0.8230.0' SectionSetFlags ${secof3} 16 ${Else} StrCmp $0 0 0 +1 ${EndIf} ${GetFileVersion} "$PROGRAMFILES\Microsoft Office\OFFICE11\WINWORD.EXE" $0 ${If} $0 >= '11.0.8237.0' SectionSetFlags ${secof4} 16 ${Else} StrCmp $0 0 0 +1 ${EndIf} ${GetFileVersion} "$PROGRAMFILES\Microsoft Office\OFFICE11\POWERPNT.EXE" $0 ${If} $0 >= '11.0.8227.0' SectionSetFlags ${secof5} 16 ${Else} StrCmp $0 0 0 +1 ${EndIf} Functionend
要注意的是:要想使用GetFileVersion 要在开头加上
!include "FileFunc.nsh"
!insertmacro GetFileVersion
否则编译时会提示GetFileVersion是无效命令。
还有对于office补丁来说有些补丁是重复替换同一个文件的,我们在做补丁包的时候,只要把最新补丁打上就可以了如
office2003-KB958436-FullFile-CHS.exe
office2003-KB955466-FullFile-CHS.exe
office2003-KB959995-FullFile-CHS.exe
这三个文件都是替换excel.exe文件其中KB959995是最新版本,只要把这个集成到补丁包中就可以了。