| Windows 7: VBS script used to overwrite, now makes (unwanted) copy |
19 Jun 2012
|
#1 | | Windows 7 Professional 32 bit San Francisco, California |
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 |
| OS Windows 7 Professional 32 bit |
19 Jun 2012
|
#2 | | Windows 7 Ultimate x64 Service Pack 1 Doncaster, UK |
Can you post a copy of the code (in text form) so that we can look at it to see if there's anything that may be causing this issue? | My System Specs | | Computer type PC/Desktop System Manufacturer/Model Number Dwarf Dwf/11/2012 OS Windows 7 Ultimate x64 Service Pack 1 CPU Intel Core-i5-3570K 4-core @ 3.4GHz (Ivy Bridge) (OC 4.2GHz) Motherboard ASRock Z77 Extreme4-M Memory 4 x 4GB DDR3-1600 Corsair Vengeance CMZ8GX3M2A1600C9B (16GB) Graphics Card 2 x AMD Radeon HD7770 1GB CrossFired (OC 1100MHz/1250MHz) Sound Card Realtek High Definition on board solution (ALC 898) Monitor(s) Displays ViewSonic VA1912w Widescreen (VGA) Screen Resolution 1440x900 Keyboard Microsoft Comfort Curve Keyboard 3000 (USB) Mouse Microsoft Comfort Mouse 3000 for Business (USB) PSU XFX Pro Series 850W Semi-Modular Case Gigabyte IF233 Cooling 1 x 120mm Front Inlet 1 x 120mm Rear Exhaust Hard Drives OCZ Agility 3 SSD 120GB SATA III x2 (RAID 0)
Samsung HD501LJ 500GB SATA II x2
Hitachi HDS721010CLA332 1TB SATA II
Iomega 1.5TB Ext USB 2.0
WD 2.0TB Ext USB 3.0 Internet Speed NetGear DG834Gv3 ADSL Modem/Router (Ethernet) ~4.0 Mb/s (O2) Antivirus Avast! 8.0.1483 Browser IE 9 Other Info Optical Drive: HL-DT-ST BD-RE BH10LS30 SATA Bluray
Lexmark S305 Printer/Scanner/Copier (USB)
CTF-430 Tablet & Pen
WEI Score: 7.7/7.9/7.4/7.4/7.9
Asus Eee PC 1011PX Netbook (Windows 7 x86 Starter) |
19 Jun 2012
|
#3 | | Windows 7 Professional 32 bit San Francisco, California |
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. Code: 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 | | OS Windows 7 Professional 32 bit |
19 Jun 2012
|
#4 | | Windows 7 Ultimate x64 SP1 clean install Italy |
Hi, the method CopyFile has a third parameter, overwrite. If it is true, it'll overwrite the file: Code: oFSO.CopyFile source, destination, True Another recommendation: as destination, don't use only path, but include also the filename (i.e., not C:\Temp but C:\Temp\MyFile).
CyberZeus | My System Specs | | System Manufacturer/Model Number Custom Build OS Windows 7 Ultimate x64 SP1 clean install CPU AMD Athlon 64 X2 6400+ Motherboard Asus M2N-E SLI Memory 4 GB Graphics Card 2 x NVidia Geforce 8600 GTS Sound Card Trust 5.1 Surround USB Monitor(s) Displays Benq FP931 19" Screen Resolution 1280x1024@32bit@75MHz Keyboard Logitech Cordless Desktop EX 100 Mouse Logitech Cordless Optical PSU 650W Hard Drives 1 x Western Digital 500GB SATA (OS installation), 2 x Seagate 320GB SATA, 1 x Seagate 250GB IDE (in external USB box), 1 x TrekStor 750GB USB Internet Speed 8192 kbps / 640 kbps |
19 Jun 2012
|
#5 | | Windows 7 Professional 32 bit San Francisco, California |
Thanks. That's interesting. But is there a reason this third parameter would be required on some systems and not others? (The differently-behaving machines are very similar, even similar Dell models purchased the same month!)
I appreciate the tip. | My System Specs | | OS Windows 7 Professional 32 bit |
19 Jun 2012
|
#6 | | Windows 7 Ultimate x64 SP1 clean install Italy |
You're welcome!
I don't know why the behaviour is different, however if the third parameter solves, use it.
CyberZeus | My System Specs | | System Manufacturer/Model Number Custom Build OS Windows 7 Ultimate x64 SP1 clean install CPU AMD Athlon 64 X2 6400+ Motherboard Asus M2N-E SLI Memory 4 GB Graphics Card 2 x NVidia Geforce 8600 GTS Sound Card Trust 5.1 Surround USB Monitor(s) Displays Benq FP931 19" Screen Resolution 1280x1024@32bit@75MHz Keyboard Logitech Cordless Desktop EX 100 Mouse Logitech Cordless Optical PSU 650W Hard Drives 1 x Western Digital 500GB SATA (OS installation), 2 x Seagate 320GB SATA, 1 x Seagate 250GB IDE (in external USB box), 1 x TrekStor 750GB USB Internet Speed 8192 kbps / 640 kbps VBS script used to overwrite, now makes (unwanted) copy problems? All times are GMT -5. The time now is 06:20 PM. | |