Go Back   PackageDeploy Application Packaging Forums > Package Development > Application Packaging > Platformsdk MSI

Reply
 
LinkBack Thread Tools Display Modes
Old 09-18-2008, 06:20 AM   #1 (permalink)
Superfreak3
Guest
 
Posts: n/a
Default Detect if Patch has been apply and prevent re-apply.....

Hi,

We have a an application that is sometimes patched by placing an .msp
in a share. If detected by our update utility, it will apply it
silently. This way, if a user leaves an old patch file there, the
attempt to fire it will be captured in a log with no user
interruption.

I digress....

Everytime a user runs the utility (occurs from workstations), if
valid, the patch keeps re-applying. Is there any way to prevent
this? Can the patch see - oh, I've already been applied here so I'll
do nothing?

The reason I ask, and I'm unclear on the actual details, but something
is being reset on user's workstations everytime this runs.

Any help, tips, assistance, etc is greatly appreciated!

We do recommend that user remove the patch file from the install share
following deployment, but this particular user cannot estimate when
all workstations will update.

THANKS IN ADVANCE!
  Reply With Quote
Old 09-18-2008, 06:20 AM   #2 (permalink)
Adrian Accinelli
Guest
 
Posts: n/a
Default Re: Detect if Patch has been apply and prevent re-apply.....

"Superfreak3" <Matt.Walker@synergis.com> wrote in message
news:1ec234de-0af1-4bd4-825e-05d0ef05def7@56g2000hsm.googlegroups.com...
> Hi,
> We have a an application that is sometimes patched by placing an .msp
> in a share. If detected by our update utility, it will apply it
> silently. This way, if a user leaves an old patch file there, the
> attempt to fire it will be captured in a log with no user
> interruption.
> I digress....
> Everytime a user runs the utility (occurs from workstations), if
> valid, the patch keeps re-applying. Is there any way to prevent
> this? Can the patch see - oh, I've already been applied here so I'll
> do nothing?
> The reason I ask, and I'm unclear on the actual details, but something
> is being reset on user's workstations everytime this runs.
> Any help, tips, assistance, etc is greatly appreciated!
> We do recommend that user remove the patch file from the install share
> following deployment, but this particular user cannot estimate when
> all workstations will update.
> THANKS IN ADVANCE!



Have your app query the Revision Number of the summary information stream of
your MSP file to get the patch's GUID. Then use MsiEnumPatchesEx (or
minimum MsiEnumPatches) to check if patch is on the machine.

If it is not on the machine you could also check that the MSP is applicable
by using MsiDeterminePatchSequence or MsiDetermineApplicablePatches. The
idea is that with patch sequencing an MSP could be superseded by a different
MSP already on the machine. Thus applying the so called "new" patch even
though it is not installed locally (MsiEnumPatchesEx returns not found)
would result in a redundant installation.

Sincerely,
Adrian Accinelli


  Reply With Quote
Old 09-18-2008, 06:20 AM   #3 (permalink)
Superfreak3
Guest
 
Posts: n/a
Default Re: Detect if Patch has been apply and prevent re-apply.....

On Apr 28, 8:54*pm, "Adrian Accinelli"
<hclnospamali...@newsgroup.nospam> wrote:
> "Superfreak3" <Matt.Wal...@synergis.com> wrote in message
>
> news:1ec234de-0af1-4bd4-825e-05d0ef05def7@56g2000hsm.googlegroups.com...
>
>
>
>
>
> > Hi,
> > We have a an application that is sometimes patched by placing an .msp
> > in a share. *If detected by our update utility, it will apply it
> > silently. *This way, if a user leaves an old patch file there, the
> > attempt to fire it will be captured in a log with no user
> > interruption.
> > I digress....
> > Everytime a user runs the utility (occurs from workstations), if
> > valid, the patch keeps re-applying. *Is there any way to prevent
> > this? *Can the patch see - oh, I've already been applied here so I'll
> > do nothing?
> > The reason I ask, and I'm unclear on the actual details, but something
> > is being reset on user's workstations everytime this runs.
> > Any help, tips, assistance, etc is greatly appreciated!
> > We do recommend that user remove the patch file from the install share
> > following deployment, but this particular user cannot estimate when
> > all workstations will update.
> > THANKS IN ADVANCE!

>
> Have your app query the Revision Number of the summary information stream of
> your MSP file to get the patch's GUID. *Then use MsiEnumPatchesEx (or
> minimum MsiEnumPatches) to check if patch is on the machine.
>
> If it is not on the machine you could also check that the MSP is applicable
> by using MsiDeterminePatchSequence or MsiDetermineApplicablePatches. *The
> idea is that with patch sequencing an MSP could be superseded by a different
> MSP already on the machine. *Thus applying the so called "new" patch even
> though it is not installed locally (MsiEnumPatchesEx returns not found)
> would result in a redundant installation.
>
> Sincerely,
> Adrian Accinelli- Hide quoted text -
>
> - Show quoted text -


Here's some vbscript code I've come across that I'm hacking away at.
It seems I get a Patch.State = 1 if the patch is applied, but it
errors on the Patch.State stuff if the patch is not applied.
I guess I can grab or catch an error (??) and, if not applied, apply
the patch. If I get 1, I know not to run the patch.

If anyone can look at this script and strip it to the bare minimum for
what I need to determine if a patch has been applied or not, that
would be greatly appreciated. ...


'// Extracting Patch Information as XML
' This script calls the MsiExtractPatchXMLData function to extract
information from a patch
' that can be used to determine if the patch applies to a target
system. The function returns
' an XML string that can be provided to MsiDeterminePatchSequence and
MsiDetermineApplicablePatches
' instead of the full patch file. The returned information can be used
to determine whether the
' patch is applicable.
'
' Usage: [CScript | WScript] MsiExtractPatchXMLData.vbs <full path
to .MSP>
' Example: cscript MsiExtractPatchXMLData.vbs "C:\Temp\patch.msp"

'// Todo:
' Fetch PatchGUID & TargetProductCode to support removal of patch
Option Explicit

Const MinMsiVersion = "3.0" '// minimal Windows Installer version
Const ERROR_SUCCESS = 0
Const ERROR_INVALID_PARAMETER = 87
Const ERROR_PATCH_PACKAGE_OPEN_FAILED = 1635
Const ERROR_PATCH_PACKAGE_INVALID = 1636
Const ERROR_PATCH_PACKAGE_UNSUPPORTED = 1637 '// This patch package
cannot be processed by the Windows Installer service. You must install
a Windows service pack that contains a newer version of the Windows
Installer service.
Const ERROR_PATCH_REMOVAL_UNSUPPORTED = 1646 '// The patch package is
not a removable patch package. Available beginning with Windows
Installer version 3.0.

Const MSIPATCHSTATE_APPLIED = 1 '// Patch is applied to this product
instance.
Const MSIPATCHSTATE_SUPERSEDED = 2 '// Patch is applied to this
product instance but is superseded.
Const MSIPATCHSTATE_OBSOLETED = 4 '// Patch is applied in this
product instance but obsolete.

Const UserSidEveryone = "S-1-1-0" '// SID for Everyone specifies
enumeration across all users in the system
Const msiInstallContextUserManaged = 1 '// Enumerate products that are
under the managed context.
Const msiInstallContextUserUnManaged = 2 '// Enumerate products that
are under the unmanaged context.
Const msiInstallContextMachine = 4 '// Enumerate products that are
under the machine account.


'Dim args : Set args = WScript.Arguments
Dim Installer
Set Installer = CreateObject("WindowsInstaller.Installer")

'// check required Windows Installer version for patch management
'If MinMsiVersion > Installer.Version Then
' WScript.Echo "Installer version: " & Installer.Version & ", Requires
minimal: " & MinMsiVersion
' WScript.Quit
'End If

'Dim ReturnCode : ReturnCode = ValidateArgument(args)
'If(ERROR_SUCCESS <> ReturnCode) Then
' DisplayErrMsg(ReturnCode)
' ShowHelp()
'End If

Dim PatchPath
PatchPath = "C:\temp\patch.msp"


Dim PatchXMLData
PatchXMLData = MsiExtractPatchXMLData(PatchPath)

Dim xmlMsiPatch
Set xmlMsiPatch = LoadXML(PatchXMLData)

Dim PatchCode
PatchCode = xmlMsiPatch.Attributes.GetNamedItem("PatchGUID").T ext

Dim ProductCode
ProductCode =
xmlMsiPatch.getElementsByTagName("TargetProductCod e").item(0).text

Dim UpdatedVersion
'UpdatedVersion =
xmlMsiPatch.getElementsByTagName("UpdatedVersion") .item(0).text

msgbox "PatchCode: " & PatchCode & vbNewLine _
& "ProductCode: " & ProductCode & vbNewLine _
& "UpdatedVersion: " & UpdatedVersion

'msgbox "cached patch file: " & Installer.PatchInfo(PatchCode,
"LocalPackage")
Dim Patch
Set Patch = Installer.Patch(PatchCode, ProductCode, "",
msiInstallContextMachine)
MsgBox Patch.State

'WScript.Echo "ProductCode: " & Patch.PatchProperty("LocalPackage")
'Set InstalledProducts = Installer.ProductsEx(PatchCode, "S-1-1-0", 4)
'For Each Product In InstalledProducts
' WScript.Echo Product.UserSid
'Next


'Dim Patch
''Set Patch = Installer.PatchInfo(PatchGUID, "State")
'Set Patch = Installer.Patch(PatchGUID, "", "S-1-1-0", 4)
'For
'WScript.Echo Patch.State

Function MsiExtractPatchXMLData(szPatchPath)
Dim Installer
Set Installer = CreateObject("WindowsInstaller.Installer")
Dim szXMLData
szXMLData = Installer.ExtractPatchXMLData(szPatchPath)

MsiExtractPatchXMLData = szXMLData
End Function

Function LoadXML(XmlData)
Dim xmlDoc : Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.async = False

If Not xmlDoc.LoadXml(XmlData) Then
Dim oErr : Set oErr = xmlDoc.parseError
Dim sErrMsg : sErrMsg = "XML Parsing Error. File: " & oErr.url & "
Reason : " & oErr.reason & " Line: " & oErr.line & ", Character: " &
oErr.linepos & ", Text: " & oErr.srcText
WScript.Echo "[" & Time & "]: " & sErrMsg
WScript.Quit
End If

Set LoadXML = xmlDoc.documentElement
End Function
  Reply With Quote
Old 09-18-2008, 06:20 AM   #4 (permalink)
Phil Wilson
Guest
 
Posts: n/a
Default Re: Detect if Patch has been apply and prevent re-apply.....

Do you know what the product version is supposed to be? In cases like this
that I've had to deal with I just look at the product version to see if it's
at the patched level or not.
--
Phil Wilson
Definitive Guide to Windows Installer
http://www.apress.com/book/view/1590592972


"Superfreak3" <Matt.Walker@synergis.com> wrote in message
news:1ec234de-0af1-4bd4-825e-05d0ef05def7@56g2000hsm.googlegroups.com...
> Hi,
>
> We have a an application that is sometimes patched by placing an .msp
> in a share. If detected by our update utility, it will apply it
> silently. This way, if a user leaves an old patch file there, the
> attempt to fire it will be captured in a log with no user
> interruption.
>
> I digress....
>
> Everytime a user runs the utility (occurs from workstations), if
> valid, the patch keeps re-applying. Is there any way to prevent
> this? Can the patch see - oh, I've already been applied here so I'll
> do nothing?
>
> The reason I ask, and I'm unclear on the actual details, but something
> is being reset on user's workstations everytime this runs.
>
> Any help, tips, assistance, etc is greatly appreciated!
>
> We do recommend that user remove the patch file from the install share
> following deployment, but this particular user cannot estimate when
> all workstations will update.
>
> THANKS IN ADVANCE!



  Reply With Quote
Old 09-18-2008, 06:20 AM   #5 (permalink)
Adrian Accinelli
Guest
 
Posts: n/a
Default Re: Detect if Patch has been apply and prevent re-apply.....

"Phil Wilson" <phil.wilson@wonderware.something.com> wrote in message
news:eI5RimvqIHA.2208@TK2MSFTNGP04.phx.gbl...
> Do you know what the product version is supposed to be? In cases like
> this that I've had to deal with I just look at the product version to
> see if it's at the patched level or not.



Makes sense but you need to know what the new level is to get this to work.
Also it only works for minor upgrades/service packs - not for hotfixes since
product version won't change. If you are in control of whole process these
are minor concerns otherwise using MSI api to query is much safer.

Sincerely,
Adrian Accinelli


  Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 08:57 AM.


vBulletin, Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright 2007-2013, PackageDeploy.com