Solved

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

Posted on 2014-01-24
5
439 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
The viewer will learn how to count occurrences of each item in an array.

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now