Windows Critical Updates Mass Installer
From NSIS Wiki
Jump to navigationJump to search
Author: Red Wine (talk, contrib) |
Description
The following example provided for the subject at this forum thread.
Requires MoreInfo plugin and implements the included with NSIS distribution, function DumpLog.
The Code
;REQUIRES MOREINFO PLUGIN http://nsis.sourceforge.net/MoreInfo_plug-in !define UPDATES_DIR "C:\Critical Updates" ;add here the real path to updates folder !define KB_CHECK "$WINDIR\$$NtUninstallKB$kbnum$$" !define LVM_GETITEMCOUNT 0x1004 !define LVM_GETITEMTEXT 0x102D Name "Windows Critical Updates Installer" Caption "$(^name)" OutFile 'updater.exe' LicenseData '${NSISDIR}\License.txt' LicenseBkColor 0xFFFFFF ShowInstDetails show var kbnum page license page instfiles Section "All in one" FindFirst $0 $1 "${UPDATES_DIR}\*.exe" loop: IfErrors done detailprint 'Found Update: $1' MoreInfo::GetUserDefined "${UPDATES_DIR}\$1" "KB Article Number" Pop $kbnum detailprint 'KB Article Number is: $kbnum' detailprint " " detailprint "Looking for: ${KB_CHECK}" IfFileExists "${KB_CHECK}\*" 0 install detailprint 'Critical Update KB$kbnum is installed' Goto next install: detailprint 'Critical Update KB$kbnum is NOT installed' detailprint 'Updating system with KB$kbnum. Please wait...' ;replace /help with required switches advisable are /quiet /norestart ExecWait "${UPDATES_DIR}\$1 /help" $3 ;/quiet /norestart Detailprint "Return value: $3" ;use return value to verify successful update SetRebootFlag true next: detailprint '...........' FindNext $0 $1 Goto loop done: FindClose $0 IfFileExists "$EXEDIR\update.log" 0 +2 Delete "$EXEDIR\update.log" ClearErrors GetTempFileName $0 Push $0 Call DumpLog IfErrors 0 +3 Delete "$0" goto +3 Rename $0 "$EXEDIR\update.log" ExecShell open "$EXEDIR\update.log" IfRebootFlag 0 +3 messagebox mb_yesno|mb_iconexclamation "Reboot required, reboot now?" idno +2 Reboot SectionEnd Function .onInit IfFileExists "${UPDATES_DIR}\*.exe" start messagebox mb_ok|mb_iconstop "no updates found at ${UPDATES_DIR}" Abort start: FunctionEnd Function DumpLog Exch $5 Push $0 Push $1 Push $2 Push $3 Push $4 Push $6 FindWindow $0 "#32770" "" $HWNDPARENT GetDlgItem $0 $0 1016 StrCmp $0 0 error FileOpen $5 $5 "w" StrCmp $5 0 error SendMessage $0 ${LVM_GETITEMCOUNT} 0 0 $6 System::Alloc ${NSIS_MAX_STRLEN} Pop $3 StrCpy $2 0 System::Call "*(i, i, i, i, i, i, i, i, i) i \ (0, 0, 0, 0, 0, r3, ${NSIS_MAX_STRLEN}) .r1" loop: StrCmp $2 $6 done System::Call "User32::SendMessageA(i, i, i, i) i \ ($0, ${LVM_GETITEMTEXT}, $2, r1)" System::Call "*$3(&t${NSIS_MAX_STRLEN} .r4)" FileWrite $5 "$4$\r$\n" IntOp $2 $2 + 1 Goto loop done: FileClose $5 System::Free $1 System::Free $3 Goto exit error: MessageBox MB_OK "error! could not create the update log" SetErrors exit: Pop $6 Pop $4 Pop $3 Pop $2 Pop $1 Pop $0 Exch $5 FunctionEnd
License
This application is provided 'as-is', without any express or implied warranty. In no event will the author be held liable for any damages arising from the use of this application.
Permission is granted to anyone to use this application for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
- The origin of this application must not be misrepresented; you must not claim that you wrote the original code. If you use this application in a product, an acknowledgment in the product documentation would be appreciated but is not required.
- Altered versions must be plainly marked as such, and must not be misrepresented as being the original application.
- This notice may not be removed or altered from any distribution.