Hi experts,
I need your help on my VBS in excel - cannot copy folder on remote server.
Below is the code.
I could get the remote server info (CPU, Memory) correctly, but cannot finish the copy folder.
Thank you very much.
BR,
Eric
-----------------------------------------------------------------------------------------------------
Option Explicit
Sub ReadOSInfo()
Dim objLocator, objWMIService, objItem, objComputer, colItems, colComputer, strComputer, strUserID, strPassword, strSID, strCI, colFolders, errResults, Wscript, ParentFolder
Dim objFSO, objFolder, objShell As Object
Dim i, j
Const wbemImpersonationLevelImpersonate = 3
Const wbemAuthenticationLevelPktPrivacy = 6
Const OverWriteFiles = True
On Error Resume Next
frmLoginForm.Show
strUserID = Trim(frmLoginForm.txtUserName.Value)
strPassword = frmLoginForm.txtPassword.Value
If frmLoginForm.Tag = 2 Then
Unload frmLoginForm
Exit Sub
End If
Unload frmLoginForm
i = 2
Do While Cells(i, 1) <> ""
strComputer = Cells(i, 1)
' strSID = Cells(i, 2)
' strCI = Cells(i, 3) '* detect if this server is CI server.
Set objLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = objLocator.ConnectServer(strComputer, "root\cimv2", strUserID, strPassword)
If Err.Number = -2147023174 Then
'MsgBox "The remote host """ & strComputer & """ does not exist or is currently shutdown", vbOKOnly, "can not connect to remote host"
ElseIf Err.Number = -2147024891 Then
MsgBox "Wrong username or password", vbOKOnly, "can not connect to remote host"
Else
'MsgBox "Error:" & CStr(Err.Number) & vbCrLf & "Reason:" & Err.Description & vbCrLf & "Source:" & Err.Source, vbOKOnly, "can not connect to remote host"
End If
If Err.Number <> 0 Then
Cells(i, 6) = "Error # " & CStr(Err.Number) & " Err.Details: " & Err.Description
Exit Do
End If
objWMIService.Security_.ImpersonationLevel = wbemImpersonationLevelImpersonate
objWMIService.Security_.AuthenticationLevel = wbemAuthenticationLevelPktPrivacy
Set colComputer = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
If Err.Number <> 0 Then
Cells(i, 4) = "Error # " & CStr(Err.Number) & " " & Err.Description
Exit Do
End If
For Each objComputer In colComputer
Cells(i, 4) = Int((objComputer.TotalPhysicalMemory) / 1048576) + 1
Cells(i, 5) = objComputer.NumberOfProcessors
Next
'3. WMI COPY FOLDER
Set colFolders = objWMIService.ExecQuery("Select * from Win32_Directory where Name = 'D:\\test'")
If Err.Number <> 0 Then
Cells(i, 6) = "Error # " & CStr(Err.Number) & " Win32_Directory " & Err.Description
Exit Do
End If
For Each objFolder In colFolders
errResults = objFolder.Copy("D:\EXE_NEW")
Wscript.Echo errResults
Next
i = i + 1
Loop
End Sub
Bookmarks