I'm having difficulty with my script which will should copy files between 2 different PC's.
Code:
strComputer = "."
set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
("SELECT * FROM __InstanceCreationEvent WITHIN 10 WHERE " _
& "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _
& "TargetInstance.GroupComponent= " _
& "'Win32_Directory.Name=""\\\\\\\\data\\\\users\\\\test""'")
Do
Set objLatestEvent = colMonitoredEvents.NextEvent
strFile = objLatestEvent.TargetInstance.PartComponent
strFile = Replace(Mid(strFile, InStr(strFile, Chr(34)) + 1), "\\", "\")
strFile = Left(strFile, Len(strFile) - 1)
objFSO.CopyFile strFile, "c:\test\"
Loop Using the local connection above, it doesn't seem that I can use a UNC connection line in Win32_Directory.Name. However, if I change "\\\\\\\\data\\\\users\\\\test" to "Z:\\\\test" (by mapping \\data\users to Z: ), it will work fine. But I don't want to use mapped drive letters.
If I change strComputer to create a remote connection to the remote machine:
Code:
strComputer = "remotemachine"
set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
("SELECT * FROM __InstanceCreationEvent WITHIN 10 WHERE " _
& "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _
& "TargetInstance.GroupComponent= " _
& "'Win32_Directory.Name=""c:\\\\test""'")
Do
Set objLatestEvent = colMonitoredEvents.NextEvent
strFile = objLatestEvent.TargetInstance.PartComponent
strFile = Replace(Mid(strFile, InStr(strFile, Chr(34)) + 1), "\\", "\")
strFile = Left(strFile, Len(strFile) - 1)
objFSO.CopyFile strFile, "\\data\test\"
Loop The code runs fine until the loop, which returns a disk not ready error when it tries to copy the file. Permissions on \\data\test are set to Everyone - Full. I have also tried "\\data\users\test" and "\\data\c$\users\test\"
The end result I am looking for is:
Have a script run every so often on the server (data) and check for new files on 5 remote stations. If a new file is found, copy it to the server.
Any help on this would be appreciated.
TIA