Trying filecopy via WMI fail (got security issues)

G

Guest

I am trying to achieve the following
- via VBA code (in access) on computer A
- initiate a copy on computer B
- from a share on computer C (or from an other local disk on B)
- to a local disk on computer B

From the examples I found the information to do this using WMI and initially
it worked when doing local disk to local disk (on computer B) but as soon as
I need to access the file on the share I run into trouble.

Initially I didn't do the share mapping hence the problem (I assume)
Afterwards I did the mapping without results
Same problem remains: filecopy fails 'target not available' (error code 9)
Finally I added the Impersonation and than I run into trouble
It gives an error on this line Set oFile = objServices.Get("cim_datafile='"
& RemoteSourceFile & "'")
Error 0x80070721 security package specific error

Here is the code

Public Function DoRemoteCopy(RemoteServer As String, RemoteSourceFile As
String, RemoteDestinationFile As String)

Dim objLocator As Object
Dim objServices As Object
Dim objWMIService As Object
Dim objMapDriveService As Object

Dim oFile As Object
Dim lRet As Integer
Dim lPID As Integer

Set objLocator = CreateObject("Wbemscripting.SWbemLocator")
Set objServices = objLocator.ConnectServer(RemoteServer, "root\cimv2",
RemoteServer & "\meta", "meta")
objServices.Security_.ImpersonationLevel = 4

Set oFile = objServices.Get("cim_datafile='" & RemoteSourceFile & "'")
Set objMapDriveService = objServices.Get("Win32_Process")
lRet = objMapDriveService.Create("net use P: """ &
"\\pc_meta01\PlateQueueManager" & """", Null, Null, lPID)
If lRet <> 0 Then
MsgBox "Map Drive Failed Returned Code : " & lRet
End If

lRet = oFile.Copy(RemoteDestinationFile)
If lRet <> 0 Then
MsgBox "File Copy Failed Returned Code : " & lRet
End If
DoRemoteCopy = lRet

End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top