|
Answer» Hello, Is it possible to REPLACE a file via a batch file BASED on the file version. I currently have an .exe v1 on every pc in the company which I need to replace with .exe v2. I need to deploy this file via ACTIVE directory in the startup SCRIPT. The first version I sent out was sent out with this batch file
@echo off
if EXIST c:\server.exe goto end xcopy /Y \\Server1\xml\server.exe c:\ c:\xmlserver.exe endif
:end exit
I now need to replace this .exe with a new one.There are many ways to do this, this one might be the simplest:
Code: [Select]Const OverwriteExisting = TRUE
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objLocalFile = objFSO.GetFile("c:\server.exe") dtmLocalDate = objLocalFile.DateLastModified
Set objServerFile = objFSO.GetFile("\\server1\xml\server.exe") dtmServerDate = objServerFile.DateLastModified
If dtmLocalDate < dtmServerDate Then objFSO.CopyFile objServerFile.Path, objLocalFile.Path, OverwriteExisting End If
Save file with a vbs extension and run as cscript scriptname.vbs.
Curious though, how did your batch file run, considering batch does not support if/endif constructs?
The File System Object has other methods to compare actual file versions instead of dates. Let us know if you need help with that.
Hope this helps. 8-)
|