+ Reply to Thread
Results 1 to 2 of 2

cannot copy folder on remote server

Hybrid View

  1. #1
    Registered User
    Join Date
    02-16-2013
    Location
    Shanghai
    MS-Off Ver
    Excel 2007
    Posts
    1

    cannot copy folder on remote server

    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
    Last edited by JBeaucaire; 02-16-2013 at 09:32 AM. Reason: Changed your username and Added code tags, as per forum rules. Don't forget! Please read the forum rules!

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: cannot copy folder on remote server

    I can't imagine it is correct that your computer has D: mapped with both a single \ and a double slash.

    D:\\test
    D:\EXE_NEW

    I'd suggest you make them both a single slash and try again, if that fails make them both a double. I'd think they would need to be the same if they are the same drive.


    NOTE: I have changed your username to just elulue to eliminate the email syntax, use that to login from now on.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1