Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copying a file using WMI

Status
Not open for further replies.

spence74

Programmer
Jul 16, 2004
34
0
0
US
I have another WMI question. How do you use the WMI to copy a file from a remote server to a local PC? I have the following code, which does not generate any errors yet it does not copy the file either. Someone please help!!

Dim objWMI, objLocator, objWMIFiles, objWMIFile
Dim strUpdateDirectory As String
Dim strFrameworkPath As String
Dim strSQLServer As String
Dim strString As String

strSQLServer = "CPSPE17"

Set objLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMI = objLocator.ConnectServer(strSQLServer, "root/cimv2", username and password omitted)
objWMI.Security_.ImpersonationLevel = 3


Set objWMIFiles = objWMI.execquery("ASSOCIATORS OF {Win32_Directory.Name='E:\Framework\Test_JDS'} WHERE ResultClass = CIM_DataFile")

strString = "C:\Test_JDS\Test_JDS.txt"
For Each objWMIFile In objWMIFiles
If objWMIFile.FileName = LCase("Test_JDS") Then
objWMIFile.Copy strString
End If
Next
Set objWMI = Nothing
Set objWMIFile = Nothing
Set objWMIFiles = Nothing
 
I have some new information into my problem. When reading the return value from the call to the Copy method, I found that it was returning a 9 - invalid object. I changed the strString variable to "C:\" and re-ran the routine and I got a return value of 0 - No error.

This brings me to a new issue. The file got copied to the C drive on the remote machine. How do I specify that the file needs to go to the C drive on my local PC?
 
cim_datafile copy method does not support unc path. You can make a local instance of scripting.filesystemobject and then connect to the remote via the admin share (C$) and copy the remote file to your local. fso will support unc path.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top