Dim nodeName
Dim argsObj
Set argsObj=WScript.Arguments
If argsObj.Count=1 Then
    nodeName = argsObj(0)
    WScript.echo "usage: cscript.exe copyfiles.vbs <nodeName>"
    WScript.Quit (1)
End If
Set objWMIService = GetObject _
    ("winmgmts:\" & nodeName & "rootcimv2:Win32_Process")
errReturn = objWMIService.Create _
    ("cmd.exe /c md c:Temp", Null, Null, intProcessID)
Wscript.Echo errReturns
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\" & nodeName & "rootcimv2")
Set colFiles = _
    objWMIService.ExecQuery("Select * From CIM_DataFile Where Drive = 'C:' and Path = '\Scripts\' and FileName Like 'coda%'") 
	'Wscript.Echo colFiles.Count echo number of files
For Each objFile in colFiles
    strNewFile = "C:Temp" & objFile.FileName & "." & objFile.Extension 
   	errResults = objFile.Copy(strNewFile)
	Wscript.Echo errResults 'displaying error code


This script allow copy selected files on a remote machine

usage : cscript copyfiles.vbs computername


The script is doing the following:

  1. Create Folder Named C:temp this done by this statement ” (“cmd.exe /c md c:Temp”, Null, Null, intProcessID)
  2. Select files located on drive C: on folder named scripts and all files starts with coda this is done by ” objWMIService.ExecQuery(“Select * From CIM_DataFile Where Drive = ‘C:’ and Path = ‘\Scripts\’ and FileName Like ‘coda%'”) ”
  3. Writes those files into folder c:temp “strNewFile = “C:Temp” & objFile.FileName & “.” & objFile.Extension “
Previous Article
Next Article