Skip to content

Instantly share code, notes, and snippets.

@brianfgonzalez
Created October 13, 2016 14:32
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save brianfgonzalez/c38cbe60000b2ac29e87970a1617bd99 to your computer and use it in GitHub Desktop.
Save brianfgonzalez/c38cbe60000b2ac29e87970a1617bd99 to your computer and use it in GitHub Desktop.
' ScriptCryptor Project Options Begin
' HasVersionInfo: No
' Companyname:
' Productname:
' Filedescription:
' Copyrights:
' Trademarks:
' Originalname:
' Comments:
' Productversion: 0. 0. 0. 0
' Fileversion: 0. 0. 0. 0
' Internalname:
' Appicon:
' AdministratorManifest: No
' ScriptCryptor Project Options End
Dim oMsi,oFso,oWShell
Dim Patches,SumInfo
Dim patch,record,msp
Dim qView
Dim sTargetFolder,sMessage
Const OFFICEID = "000-0000000FF1CE}"
Const PRODUCTCODE_EMPTY = ""
Const MACHINESID = ""
Const MSIINSTALLCONTEXT_MACHINE = 4
Const MSIPATCHSTATE_APPLIED = 1
Const MSIOPENDATABASEMODE_PATCHFILE = 32
Const PID_SUBJECT = 3 'Displayname
Const PID_TEMPLATES = 7 'PatchTargets
Set oMsi = CreateObject("WindowsInstaller.Installer")
Set oFso = CreateObject("Scripting.FileSystemObject")
Set oWShell = CreateObject("Wscript.Shell")
'Create the target folder
sTargetFolder = oWShell.ExpandEnvironmentStrings("C:\")&"Office2013Updates"
If Not oFso.FolderExists(sTargetFolder) Then oFso.CreateFolder sTargetFolder
sMessage = "Patches are being copied to the C:\Office2013Updates folder." & vbCrLf & "A Windows Explorer window will open after the script has completed."
oWShell.Popup sMessage,20,"Office Updates Capture - www.techygeekshome.co.uk"
'Get all applied patches
Set Patches = oMsi.PatchesEx(PRODUCTCODE_EMPTY,MACHINESID,MSIINSTALLCONTEXT_MACHINE,MSIPATCHSTATE_APPLIED)
On Error Resume Next
'Enum the patches
For Each patch in Patches
If Not Err = 0 Then Err.Clear
'Connect to the patch file
Set msp = oMsi.OpenDatabase(patch.PatchProperty("LocalPackage"),MSIOPENDATABASEMODE_PATCHFILE)
Set SumInfo = msp.SummaryInformation
If Err = 0 Then
If InStr(SumInfo.Property(PID_TEMPLATES),OFFICEID)>0 Then
'Get the original patch name
Set qView = msp.OpenView("SELECT `Property`,`Value` FROM MsiPatchMetadata WHERE `Property`='StdPackageName'")
qView.Execute : Set record = qView.Fetch()
'Copy and rename the patch to the original file name
oFso.CopyFile patch.PatchProperty("LocalPackage"),sTargetFolder&"\"&record.StringData(2),TRUE
End If
End If 'Err = 0
Next 'patch
oWShell.Run "explorer /e,"&chr(34)&sTargetFolder&chr(34)
@DCiprut
Copy link

DCiprut commented Aug 7, 2017

Sorry but his does not seem to work on C2R (click to run) installations. Results in empty update file, in spite there have been plenty of updates.
Is there something I miss. Do we have to change some parms (Machine SID, OfficeID etc.) ?

@Simpuhl
Copy link

Simpuhl commented Jun 16, 2018

Does this work for 2016? Your script is named 2016 but references office 2013 in the script itself

@baardhermansen
Copy link

Does this work for 2016? Your script is named 2016 but references office 2013 in the script itself

I'm sure you already have your answer, but just in case you don't: Yes, this work very well with Office 2016.

@baardhermansen
Copy link

Sorry but his does not seem to work on C2R (click to run) installations. Results in empty update file, in spite there have been plenty of updates.
Is there something I miss. Do we have to change some parms (Machine SID, OfficeID etc.) ?

C2R does not work anything at all like MSI installations, so you can't harvest updates.
You have to run the tool like you did the very first time, to get a hold of updated installation files.

@elsenandy
Copy link

Hi, would this also be possible with Office 2013 ProPlus Language Packs? I am not able to find anything similar for Languagepacks.

Best regards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment