Solved

Execute all updates in a folder if the file version is lower then the current version

Posted on 2014-01-24
5
444 Views
Last Modified: 2014-01-27
Hello,
I am trying to create a script that will install all update files ending with the msp extension if the file version is lower then 9.5.4
I wrote the following script but I get that a colFiles.GetVersion method or property is not supported by this object error, what would be the correct way of addressing the task to get the version of each file in a folder

As a next step I like to check and compare the version of the file in the folder with the version of the executable file of an already installed application.



Dim WshShell, oExec, strCurrentVersion, strFileVersion
strCurrentVersion = "9.5.4"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("\\Server\ApplicationShare")
Set colFiles = objFolder.Files
Set colVersion = colFiles.GetFileVersion

	For Each objFile in colFiles 
		
		IF right(objFile.Name,3) = "msp" Then
    			IF colVersion  < strCurrentVersion Then
			
				Wscript.Echo(objFile.Path)
				'Set WshShell = CreateObject("WScript.Shell")
				'Set oExec = WshShell.Exec("msiexec /p " & objFile.path & " /norestart /qb REINSTALLMODE=ecmus REINSTALL=ALL") 'Execute Update
	
				
					'Do While oExec.Status = 0
     						'WScript.Sleep 100
					'Loop
			End IF

		End IF
		
Next

Open in new window

0
Comment
Question by:David
  • 2
  • 2
5 Comments
 
LVL 8

Assisted Solution

by:TheNautican
TheNautican earned 250 total points
ID: 39808054
Strangely, this has not come up before in my travels...so i had to do some research. I'm on the linux box at the moment but did find this...

http://msdn.microsoft.com/en-us/library/b4e05k97%28v=vs.84%29.aspx 

It shows passing in the file as an argument. Hope this gets you in the right direction. When i get on the windows machine I'll test this out myself. Eventually I'm sure I'll need this.

Regards,
-Naut


*** EDIT ***
This code worked just fine for me. Change to suit your needs.

Dim WshShell, oExec, strCurrentVersion, strFileVersion
strCurrentVersion = "9.5.4"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("c:\users\aj\Downloads\")
Set colFiles = objFolder.Files
'Set colVersion = colFiles.GetFileVersion

      For Each objFile in colFiles
            
            IF right(objFile.Name,3) = "exe" Then
                      IF objFSO.GetFileVersion( objFile.Path )  < strCurrentVersion Then
                      
                      'strVersion = objFSO.GetFileVersion( objFile.Path )
                  
                        Wscript.Echo(objFile.Path)
                        Wscript.Echo(objFile.Name)
                        Wscript.Echo( objFSO.GetFileVersion( objFile.Path ) )
                        'Set WshShell = CreateObject("WScript.Shell")
                        'Set oExec = WshShell.Exec("msiexec /p " & objFile.path & " /norestart /qb REINSTALLMODE=ecmus REINSTALL=ALL") 'Execute Update
      
                        
                              'Do While oExec.Status = 0
                                         'WScript.Sleep 100
                              'Loop
                  End IF

            End IF
            
Next
0
 
LVL 32

Expert Comment

by:Robberbaron (robr)
ID: 39809441
but the problem remains, how to get the file version of the MSP file (or its contents)

only exe and dll files seem to expose the version number.
msp files on my system have a 'revision number' under details but this is a GUID , not a version.
0
 

Author Comment

by:David
ID: 39811542
Thank you very much Naut and Robberbaron

I am Sorry for the confusion, I completely overlooked that there is no version info on the msp files but I found on closer look the last 3 digits in the revision number from  the MSP files I am dealing with (Adobe Acrobat Updates) represent the version.

I tried to get the last 3 digits to a string using the FSOfile Object (http://technet.microsoft.com/en-us/library/ee692828.aspx) but couldn't get it to work


Not sure if this is correct, I found some info suggesting that the FSOFile.dll needed dos not exist anymore in Windows 7.
0
 
LVL 32

Accepted Solution

by:
Robberbaron (robr) earned 250 total points
ID: 39811679
I think you meant to type DSOFile; it doesnt exist by default though can be downloaded as you noted , including a 64bit version. http://www.keysolutions.com/blogs/kenyee.nsf/d6plinks/KKYE-79KRU6 
just need to ensure you register them correctly....  the 64bit one to win\sys32,  the 32bit one to win\syswow64

what script code are you using at the moment ?  as my work with dsofile is from an app (VB6 & C#)   is the "revision number" exposed as a Summary Property or a Custom one ?
0
 

Author Comment

by:David
ID: 39812150
Thank you, I downloaded and registered the Dll and it works very nicely now
unfortunately I might not be able to get much use out of it as the environment I like to use it in is very restrictive and distributing the dll will require to go through a bureaucratic change management  process, do you know of a way that would work with the default w7 32/64 environment?

Many Thanks!

PS: the code used

Dim WshShell, oExec, strCurrentVersion, strFileVersion, objProperty
strCurrentVersion = "953"
Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFolder = objFSO.GetFolder("\\Server\AppShare")
Set colFiles = objFolder.Files

      For Each objFile in colFiles 
            
            If right(objFile.Name,3) = "msp" Then
		Set objPropertyReader = CreateObject("DSOFile.OleDocumentProperties")
	    	objPropertyReader.Open(objFile.Path)
                strFileVersion = left( Right ( objPropertyReader.SummaryProperties.RevisionNumber, 4 ), 3 )
                If strFileVersion < right(strCurrentVersion,3) Then
		          
                        Wscript.Echo(objFile.Path)
                        Wscript.Echo(strCurrentVersion)
                        Wscript.Echo(objPropertyReader.SummaryProperties.RevisionNumber)
                        'Wscript.Echo( strFileVersion )
                        'Set WshShell = CreateObject("WScript.Shell")
                        'Set oExec = WshShell.Exec("msiexec /p " & objFile.path & " /norestart /qb REINSTALLMODE=ecmus REINSTALL=ALL") 'Execute Update
      
                        
                              'Do While oExec.Status = 0
                                         'WScript.Sleep 100
                              'Loop
              objPropertyReader.Close
                 End IF

            End IF
            
Next

Open in new window

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
This article will show, step by step, how to integrate R code into a R Sweave document
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question