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

Re: How to copy Files from one computer to another using Win32_Directo by Richard

Richard
Fri Mar 21 13:25:24 CDT 2008

I think the key is that the value of FileName in the link you gave is
relative to the machine where the file object resides. For example, if the
VBScript statement is:

intRC = objSourceFile.Copy(strFilePath)

Then objSourceFile is an object reference to a file on a computer, and
strFilePath is relative to this same computer. As far as I can tell, UNC
paths are not allowed for strFilePath. If objSourceFile refers to a file on
your computer, you can map a drive and copy the file to another computer,
since the path would be relative to your computer. However, if objSourceFile
refers to a file on a remote computer, you can only copy to another location
on that computer.

I'm not positive about this, but I have found no WMI examples that copy
files except from the local computer to a remote computer, and these
examples map a drive letter to the remote computer. I have never gotten UNC
paths to work with the Copy method.

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--

"Marceepoo" <36c53a08-2073470544@news.postalias> wrote in message
news:314F6D56-C164-499F-8BA5-1E8F956F1B12@microsoft.com...
> 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
>