Hi. I can copy a file (using Win32_Directory) from one folder to another,
within one computer. But I can't figure out how to copy a file from Computer
A to Computer B.
I want to learn how to use Win32_Directory to copy files from one computer
to another (instead of using the filesystem object, which I [mis-?]understand
is less reliable on remote computers). Also, I'm hoping that learning
Win32_Directory usage will facilitate my learning the ins & outs of wmi.
(I'm a masochist.)
The code below shows all the (various wrong) ways (that I dreamed up, and
actually) attempted to use Win32_Directory to copy files from one computer to
another.
I'd appreciate it very much if anyone could:
1. "Show me the way ..." to copy a file using Win32_Directory, and/or
2. Suggest where I might find an example, AND where I could learn more
about how it is possible to deduce the answer to my question from the MSDN
reference pages, e.g.:
http://msdn2.microsoft.com/en-us/library/aa389347(VS.85).aspx
I really do want to learn how to find more of these answers on my own, w/o
imposing on other peoples' time.
Anyway, thanks again for the help you folks give people like me. My failed
attempts at coding this by myself follows below....
Marceepoo
'Copy Files from one computer to another using Win32_Directory.
'
'
strComputer01 = "light"
Set objWMIService01 = GetObject("winmgmts:\\" & strComputer01 & "\root\cimv2")
strComputer02 = "."
Set objWMIService02 = GetObject("winmgmts:\\" & strComputer02 & "\root\cimv2")
Set colFileList01 = objWMIService01.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='C:\Apps\Deeleet02'} Where " _
& "ResultClass = CIM_DataFile")
Set colFileList02 = objWMIService01.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='C:\Apps\Deeleet03'} Where " _
& "ResultClass = CIM_DataFile")
iTeration = 16
Do While iTeration > 0
If iTeration = 1 Then
sTargetDir = "c:\Apps\Deeleet03\" & iTeration
Call KopyFile
ElseIf iTeration = 2 Then
sTargetDir = "\\" & strComputer02 & "\\c$\\Apps\\Deeleet03\\" & iTeration
Call KopyFile
ElseIf iTeration = 3 Then
sTargetDir = "\\" & strComputer02 & "\\c\\Apps\\Deeleet03\\" & iTeration
Call KopyFile
ElseIf iTeration = 4 Then
sTargetDir = "\\" & strComputer02 & "\c\Apps\Deeleet03\" & iTeration
Call KopyFile
ElseIf iTeration = 5 Then
sTargetDir = "\\" & strComputer02 & "\c$\Apps\Deeleet03\" & iTeration
Call KopyFile
ElseIf iTeration = 6 Then
sTargetDir = "\\" & strComputer02 & "\c$\Apps\Deeleet03\" & iTeration
Call KopyFile
ElseIf iTeration = 7 Then
sTargetDir = "\\" & strComputer02 & "\c$\Apps\Deeleet03\" & iTeration
Call KopyFile
ElseIf iTeration = 8 Then
sTargetDir = "\\" & strComputer02 & "\c:\Apps\Deeleet03\" & iTeration
Call KopyFile
ElseIf iTeration = 9 Then
sTargetDir = strComputer02 & "\\c$\\Apps\\Deeleet03\\" & iTeration
Call KopyFile
ElseIf iTeration = 10 Then
sTargetDir = strComputer02 & "\\c\\Apps\\Deeleet03\\" & iTeration
Call KopyFile
ElseIf iTeration = 11 Then
sTargetDir = strComputer02 & "\c\Apps\Deeleet03\" & iTeration
Call KopyFile
ElseIf iTeration = 12 Then
sTargetDir = strComputer02 & "\c$\Apps\Deeleet03\" & iTeration
Call KopyFile
ElseIf iTeration = 13 Then
sTargetDir = strComputer02 & "\c$\Apps\Deeleet03\" & iTeration
Call KopyFile
ElseIf iTeration = 14 Then
sTargetDir = strComputer02 & "\c$\Apps\Deeleet03\" & iTeration
Call KopyFile
ElseIf iTeration = 15 Then
sTargetDir = strComputer02 & "\c$\Apps\Deeleet03\" & iTeration
Call KopyFile
End If
iTeration = iTeration - 1
Loop
Sub KopyFile()
For Each oFile01 In colFileList01
strNewName = sTargetDir & "pl-" & iTeration & "-" & _
oFile01.FileName & "." & oFile01.Extension
errResult = oFile01.copy(strNewName)
Next
End Sub
Sub KopyFile()
For Each oFile02 In colFileList02
strNewName = sTargetDir & "pl-" & iTeration & "-" & _
oFile01.FileName & "." & oFile01.Extension
errResult = oFile01.copy(strNewName)
Next
End Sub