Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

920 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

11 Experts available now in Live!

Get 1:1 Help Now