-----copyfiles.vbs----
------Dim nodeNameDim argsObjSet argsObj=WScript.ArgumentsIf argsObj.Count=1 ThennodeName = argsObj(0)ElseWScript.echo "usage: cscript.exe copyfiles.vbs <nodeName>"WScript.Quit (1)End IfSet objWMIService = GetObject _("winmgmts:\\" & nodeName & "\root\cimv2:Win32_Process")errReturn = objWMIService.Create _("cmd.exe /c md c:\Temp", Null, Null, intProcessID)Wscript.Echo errReturnsSet objWMIService = GetObject("winmgmts:" _& "{impersonationLevel=impersonate}!\\" & nodeName & "\root\cimv2")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 filesFor Each objFile in colFilesstrNewFile = "C:\Temp\" & objFile.FileName & "." & objFile.ExtensionerrResults = objFile.Copy(strNewFile)Wscript.Echo errResults 'displaying error codeNext
This script allow copy selected files on a remote machine
usage : cscript copyfiles.vbs computername
Notes:
The script is doing the following:
- Create Folder Named C:\temp this done by this statement " ("cmd.exe /c md c:\Temp", Null, Null, intProcessID)
- 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%'") "
- Writes those files into folder c:\temp “strNewFile = "C:\Temp\" & objFile.FileName & "." & objFile.Extension “
3 comments:
Why don't you just get psexec and do the required tasks "directly" on the remote node - this scripted way for every single operation you need a special piece of code ...
The one who requested the script, was asking for a native windows technology without downloading other tools.
great idea, to use VB. when I faced a problem how to find all duplicates on WindowsXP, I tried first MS SyncToy, as a free and vendor tool. but it fails too often, not reliable. thus, I wrote a script on batch... but! #fc also fails to compare two files in many conditions, so I had to write some replacement in C :)
Post a Comment