'******************************************************************************** ' CAC ENT Preview Update Created on 4/14/2014 by Paul D'Amato ' ' This file will download updates to the CAC XAP file and Version File ' and keep a log of what was downloaded, when it was downloaded, and ' when it was copied to the right directory. '******************************************************************************** Option Explicit 'Const INFORMATION = 4 Const ForAppending = 8 Const Platform = "Preview" Const SingleSol = "singlesolution.client.xap" Const CACVersion = "CaCVersion.txt" Const wget = "C:\Program Files\GnuWin32\wget\wget.exe" Const secureProtocol = "--secure-protocol=auto" Const noCheckCert = "--no-check-certificate" Const targetPath = "\\omt4\sd\pjd14\DeskCAC\Preview" Dim fso,WshShell Dim currentDirectory Dim currentFileName Dim objCurrentFile Dim logFile Dim objLogFile Dim objDownloadFIle Dim iPosition Dim wgetURL Dim runWGET Dim fileSize Set fso = WScript.CreateObject("Scripting.FileSystemObject") Set WshShell = WScript.CreateObject("Wscript.Shell") ' ***** Get A Log File currentDirectory = Wscript.ScriptFullName Set objCurrentFile = fso.GetFile(currentDirectory) currentDirectory = fso.GetParentFolderName(objCurrentFile) iPosition = InStr(objCurrentFile.Name, ".vbs") logFile = Left(objCurrentFile.Name, iPosition - 1) & " log " & Year(Now) If Len(Month(Now)) = 1 then logFile = logFile & "0" & Month(Now) & ".log" Else logFile = logFile & Month(Now) & ".log" End If logFile = currentDirectory & "\" & logFile If fso.FileExists(logFile) then Set objLogFile = fso.OpenTextFile(logFile, ForAppending) Else Set objLogFile = fso.CreateTextFile(logFile, True) End If objLogFile.WriteLine(Now & ": Start CAC XAP file and Version File Update") ' ***** Use WGET to get the current version of SingleSOlution.Client.XAP wgetURL = "https://" & _ Platform & _ "cac.optuminsight.com/ui/" & _ Platform & _ "/ClientBin/" & _ SingleSol ' chr(34) & "--output-file=get_singl.txt" & chr(34) & " " & _ runWGET = chr(34) & wget & chr(34) & " " & _ chr(34) & "-b" & chr(34) & " " & _ chr(34) & "-q" & chr(34) & " " & _ chr(34) & secureProtocol & chr(34) & " " & _ chr(34) & noCheckCert & chr(34) & " " & _ chr(34) & wgetURL & chr(34) objLogFile.WriteLine(Now & ": " & runWGET) WshShell.Run runWGET ' ******* This line is written to the log file. Do While not fso.FileExists(currentDirectory & "\" & singleSol) ' **** This loop is where we hang because nothing is 'is coming back from WGET. Wscript.Sleep 1000 Loop set objDownloadFile = fso.GetFile(currentDirectory & "\" & SingleSol) Do fileSize = objDownloadFile.Size Wscript.Sleep 1000 Loop While objDownloadFile.Size <> fileSize ObjLogFile.WriteLine(Now & ": " & SingleSol & " Date Modified - " & objDownloadFile.DateLastModified) ' ***** Use WGET to get the current version of CaCversion.txt wgetURL = "https://" & _ Platform & _ "cac.optuminsight.com/ui/" & _ Platform & _ "/ClientBin/" & _ CACVersion runWGET = chr(34) & wget & chr(34) & " " & _ chr(34) & secureProtocol & chr(34) & " " & _ chr(34) & noCheckCert & chr(34) & " " & _ chr(34) & wgetURL & chr(34) objLogFile.WriteLine(Now & ": " & runWGET) WshShell.Run runWGET Do While not fso.FileExists(currentDirectory & "\" & CACVersion) Wscript.Sleep 1000 Loop set objDownloadFile = fso.GetFile(currentDirectory & "\" & CACVersion) Do fileSize = objDownloadFile.Size Wscript.Sleep 1000 Loop While objDownloadFile.Size <> fileSize ObjLogFile.WriteLine(Now & ": " & CACVersion & " Date Modified - " & objDownloadFile.DateLastModified) ' ***** Move Files aka Copy and Delete - becaue moveFiles won't overwrite the destination file. fso.CopyFile currentDirectory & "\" & SingleSol, targetPath & "\" & SingleSol, True objLogFile.WriteLine(Now & ": Copy " & SingleSol & " to " & targetPath) fso.DeleteFile (currentDirectory & "\" & SingleSol) objLogFile.WriteLine(Now & ": Delete " & SingleSol) fso.CopyFile currentDirectory & "\" & CACVersion, targetPath & "\" & CACVersion, True objLogFile.WriteLine(Now & ": Copy " & CACVersion & " to " & targetPath) fso.DeleteFile (currentDirectory & "\" & CACVersion) objLogFile.WriteLine(Now & ": Delete " & CACVersion) '********** this code writes to the computer/server event log 'If WshShell.LogEvent(INFORMATION, "Loggging Event Check") then ' WScript.Echo "Log Event Written" 'Else ' WScript.Echo "Failed" 'End If '********* objLogFile.WriteLine(Now & ": " & "Done.") objLogFile.Close