|19 Jun 2012||#1|
| || |
VBS script used to overwrite, now makes (unwanted) copy
I have a simple VBS login script for all my users that checks a location on our server and updates (by overwriting) the same files on the users' PCs if the server copy is newer (FSO.CopyFile etc). This has run swimmingly for several months now, but today I discovered it ISN'T overwriting the local files, but rather creates a copy of any replaced file, in the standard Win 7 format of Filename - Copy.ext.
Is this some Windows component with its Mom Switch set on high, trying to be helpful/protective? The problem it creates is this: some of the files the script updates are VBA add-ins containing a suite of Word macros; and if 2 files in the macro-supplying folder contain same-named macros, *neither* macro of the conflicting pair is available to the user.
This is a recent change -- that is, itís not something that's been happening all along but only recently noticed.
Even stranger -- or perhaps this is a clue -- this *doesn't* happen on my home PC, which is identically equpped except for different AV programs (work=Comodo, home=Avast).
All PCs are Win 7 Pro 32-bit with Office 2010.
Any ideas? I know I could change the script to delete the to-be-updated files before overwriting, but that seems like surrendering to the vampire.
|My System Specs|
|19 Jun 2012||#3|
| || |
It's below. I hope it's decipherable but I fear it may not be. (I'm not so diligent about commenting code.) FYI the notation 'AAI' is just our shorthand for the name of the macro suite. The 'guts' of the code begins after the 'copy or update files' comment.
Dim oFSO Dim oShell Dim oAppDataFolder Set oFSO=CreateObject("Scripting.FileSystemObject") Set oServerUT = oFSO.GetFolder("Z:\Users\AAI\UT\") Set oServerSU = oFSO.GetFolder("Z:\Users\AAI\SU\") Set oShell = CreateObject("Shell.Application") Set oAppDataFolder = oShell.Namespace(&H1a&) WSF = oAppDataFolder.Self.Path & "\Microsoft\Word\Startup\" Set oShell2 = CreateObject("WScript.Shell") Hpath = oShell2.ExpandEnvironmentStrings("%HomePath%") '===set local AAI file path sAAI = "C:" & Hpath & "\AAI\" sAAIUT = sAAI & "UT" Set oAAI = oFSO.GetFolder(sAAI) Set oUserUT = oFSO.GetFolder(sAAIUT) '====copy or update files Set colFilesUT = oServerUT.Files For Each oFile In colFilesUT If Instr(oFile.Name,"~")=0 Then sLocal = Right(oFile, Len(oFile.Name) - InStrRev(oFile.Name, "\")) If Not oFSO.FileExists(oUserUT.Path & "\" & sLocal) Then 'not found on local PC, so copy oFSO.CopyFile oFile.Path, oUserUT.Path & "\" bUpdated = True Else Set oLocalFile = oFSO.GetFile(oUserUT.Path & "\" & oFile.Name) If oFile.DateLastModified > oLocalFile.DateLastModified Then 'found older on local PC, so replace oFSO.CopyFile oFile.Path, oUserUT.Path & "\" bUpdated = True End If End If End If Next Set colFilesSU = oServerSU.Files For Each oFile In colFilesSU If Instr(oFile.Name,"~")=0 Then sLocal = Right(oFile, Len(oFile.Name) - InStrRev(oFile.Name, "\")) If Not oFSO.FileExists(WSF & sLocal) Then 'not found on local PC, so copy oFSO.CopyFile oFile.Path, WSF bUpdated = True Else Set oLocalFile = oFSO.GetFile(WSF & oFile.Name) If oFile.DateLastModified > oLocalFile.DateLastModified Then 'found older on local PC, so replace oFSO.CopyFile oFile.Path, WSF bUpdated = True End If End If End If Next On Error Resume Next Set oShell = Nothing Set oShell2 = Nothing Set oFSO = Nothing Set oAppDataFolder = Nothing Set oServerUT = Nothing Set oUserUT = Nothing Set SystemSet = Nothing Set oAAI = Nothing Set oHT = Nothing Set colFilesUT = Nothing Set colFilesSU = Nothing Set oLocalFile = Nothing If bNewInstall = True Then MsgBox "Install successful." End If
|My System Specs|
|19 Jun 2012||#4|
| || |
Hi, the method CopyFile has a third parameter, overwrite. If it is true, it'll overwrite the file:
oFSO.CopyFile source, destination, True
|My System Specs|
|Similar help and support threads for2: VBS script used to overwrite, now makes (unwanted) copy|
|Windows Backup makes unwanted folders on all drives, want deleted||Backup and Restore|
|Keystroke overload for mass-copy overwrite (among others)||General Discussion|
|I Need Help To Reorder The Context Menu Script In Script Form?||Customization|
|VBS script: Cannot find script engine||General Discussion|
|Overwrite -- without Prompts||General Discussion|
|script error when running a vbs script.||Network & Sharing|
|How Can I Overwrite Drive With Win 7 32 bit to 64 bit||Installation & Setup|
|Our Sites ||Site Links ||About Us ||Find Us |
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd
All times are GMT -5. The time now is 09:50 PM.