Avatar of cutecupid
cutecupid
 asked on

Compare DLL using the version

I need to compare the dll's using the version number and copy the latest version number to destination folder.

Ex:

Source:
abc.dll 23/05/2012 1.0.0.14

Source1:
abc.dll 24/05/2012 1.0.0.15

Destination: Copy the source1 dll " Destination
VB Script

Avatar of undefined
Last Comment
RobSampson

8/22/2022 - Mon
RobSampson

Hi, I think this should cover the basic requirement.

Regards,

Rob.

strSource = "\\server\share\mydll.dll"
strDestination = "c:\program files\myapp\mydll.dll"
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(strDestination) = True Then
	If objFSO.GetFileVersion(strSource) > objFSO.GetFileVersion(strDestination) Then objFSO.CopyFile strSource, strDestination, True
End If

Open in new window

cutecupid

ASKER
Not only to a particular file. I need to check all the files in the listed folder. THat too VBScript I need....thank you
RobSampson

So you have an identical set of DLLs on a server share somewhere for comparison?  If so, then this should work, with folders specified.

Regards,

Rob.

strSource = "\\server\share\myapp\"
strDestination = "c:\program files\myapp\"
Set objFSO = CreateObject("Scripting.FileSystemObject")
If Right(strDestination, 1) <> "\" Then strDestination = strDestination & "\"
If objFSO.FolderExists(strDestination) = True Then
	For Each objFile In objFSO.GetFolder(strSource).Files
		strDestFile = strDestination & objFile.Name
		If objFSO.GetFileVersion(objFile.Path) > objFSO.GetFileVersion(strDestFile) Then objFSO.CopyFile strSource, strDestination, True
	Next
End If

Open in new window

Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
cutecupid

ASKER
Hi Rob, Thanks for your time and effort...

Fine....

The vbscript should check the dll in the server and desktop or within the desktop from the mnetioned path. Both dll's should get the file revision and compare, if the destination having old dd then it should copy the dll. Then if the dll's is not available in the destination then it should copy from the destination folder. Once the task is completed it should generate log which all files has been copied.
RobSampson

OK, try this.  It will create a log file in the path you specify.

Regards,

Rob.

Set objNetwork = CreateObject("WScript.Network")
strSource = "\\server\share\myapp\"
strDestination = "c:\program files\myapp\"
strLog = "\\server\share\DLLCopyLog_" & objNetwork.ComputerName & ".txt"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objLog = objFSO.CreateTextFile(strLog, True)
If Right(strDestination, 1) <> "\" Then strDestination = strDestination & "\"
If objFSO.FolderExists(strDestination) = True Then
	If objFSO.FolderExists(strSource) = True Then
		For Each objFile In objFSO.GetFolder(strSource).Files
			strDestFile = strDestination & objFile.Name
			If objFSO.FileExists(strDestFile) = False Then
				objFSO.CopyFile strSource, strDestination, True
				objLog.WriteLine objFile.Path & " was copied to " & strDestFile
			ElseIf objFSO.GetFileVersion(objFile.Path) > objFSO.GetFileVersion(strDestFile) Then
				objFSO.CopyFile strSource, strDestination, True
				objLog.WriteLine objFile.Path & " was copied to " & strDestFile & " because it was newer"
			Else
				objLog.WriteLine objFile.Path & " was not copied to " & strDestFile & " because it was not newer"
			End If
		Next
	Else
		objLog.WriteLine strSource & " was not found."
	End If
Else
	objLog.WriteLine strDestination & " was not found."
End If
objLog.Close

Open in new window

cutecupid

ASKER
---------------------------
Windows Script Host
---------------------------
Script:      D:\hello\dlltest.vbs
Line:      14
Char:      5
Error:      File not found
Code:      800A0035
Source:       Microsoft VBScript runtime error

---------------------------
OK  
---------------------------

Modified Code

Set objNetwork = CreateObject("WScript.Network")
strSource = "D:\hello\Source\"
strDestination = "D:\hello\Destination\"
strLog = "D:\hello\Log_" & objNetwork.ComputerName & ".txt"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objLog = objFSO.CreateTextFile(strLog, True)
If Right(strDestination, 1) <> "\" Then strDestination = strDestination & "\"
If objFSO.FolderExists(strDestination) = True Then
      If objFSO.FolderExists(strSource) = True Then
            For Each objFile In objFSO.GetFolder(strSource).Files
                  strDestFile = strDestination & objFile.Name
                  If objFSO.FileExists(strDestFile) = False Then
                        objFSO.CopyFile strSource, strDestination, True
                        objLog.WriteLine objFile.Path & " was copied to " & strDestFile
                  ElseIf objFSO.GetFileVersion(objFile.Path) > objFSO.GetFileVersion(strDestFile) Then
                        objFSO.CopyFile strSource, strDestination, True
                        objLog.WriteLine objFile.Path & " was copied to " & strDestFile & " because it was newer"
                  Else
                        objLog.WriteLine objFile.Path & " was not copied to " & strDestFile & " because it was not newer"
                  End If
            Next
      Else
            objLog.WriteLine strSource & " was not found."
      End If
Else
      objLog.WriteLine strDestination & " was not found."
End If
objLog.Close
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER CERTIFIED SOLUTION
RobSampson

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
cutecupid

ASKER
Yes, its working fine...Final query on the question
Will it work when comparing 2 different servers folders?
cutecupid

ASKER
Thanks Rob...Very much appreciated.
RobSampson

No problem. Thanks for the grade.

It will work from any source folder to any destination folder.  For example, if you specify
strSource = "\\servera\masterfiles\"
strDestination = "\\server\backupfiles\"

it will copy the files from the masterfiles folder to the backupfiles folder.

Regards,

Rob.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
cutecupid

ASKER
Hi Rob, Its not comparing the subfolders. Can you pls modify the script for comparing sub folders too.
RobSampson

OK, I've got to run, so I rushed this, but hopefully it works.

Rob.

Set objNetwork = CreateObject("WScript.Network")
strSource = "D:\hello\Source\"
strDestination = "D:\hello\Destination\"
strLog = "D:\hello\Log_" & objNetwork.ComputerName & ".txt"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objLog = objFSO.CreateTextFile(strLog, True)
If Right(strDestination, 1) <> "\" Then strDestination = strDestination & "\"

CopyNewerDLLs strSource, strDestination

objLog.Close

Sub CopyNewDLLs(strSourceF, strDestinationF)
	If objFSO.FolderExists(strDestinationF) = True Then
	      If objFSO.FolderExists(strSourceF) = True Then
	            For Each objFile In objFSO.GetFolder(strSourceF).Files
	                  strDestFile = strDestinationF & objFile.Name
	                  If objFSO.FileExists(strDestFile) = False Then
	                        objFSO.CopyFile objFile.Path, strDestFile, True
	                        objLog.WriteLine objFile.Path & " was copied to " & strDestFile
	                  ElseIf objFSO.GetFileVersion(objFile.Path) > objFSO.GetFileVersion(strDestFile) Then
	                        objFSO.CopyFile objFile.Path, strDestFile, True
	                        objLog.WriteLine objFile.Path & " was copied to " & strDestFile & " because it was newer"
	                  Else
	                        objLog.WriteLine objFile.Path & " was not copied to " & strDestFile & " because it was not newer"
	                  End If
	            Next
	      Else
	            objLog.WriteLine strSourceF & " was not found."
	      End If
	      For Each objSubFolder In objFSO.GetFolder(strSourceF).SubFolders
	      	CopyNewDLLs objSubFolder.Path, strDestinationF & objSubFolder.Name & "\"
	      Next
	Else
	      objLog.WriteLine strDestinationF & " was not found."
	End If
End Sub

Open in new window

cutecupid

ASKER
---------------------------
Windows Script Host
---------------------------
Script:      D:\hello\dlltest.vbs
Line:      10
Char:      1
Error:      Type mismatch: 'CopyNewerDLLs'
Code:      800A000D
Source:       Microsoft VBScript runtime error

---------------------------
OK  
---------------------------
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
RobSampson

Sorry, small typo.  On line 10, change this
CopyNewerDLLs strSource, strDestination

to this
CopyNewDLLs strSource, strDestination

Rob.