|
Each contribution is licensed to you under a License Agreement by its owner, not Microsoft. Microsoft does not guarantee the contribution or purport to grant rights to it.
|
Categories |
Copy a File From One Remote Computer to a Second Remote Computer(Community)
Script Code
VBScript
'* you must assume there is some letter unused you can map too
'* or you could add something to try to unmap a drive first
'* NOTE: there is no way in wmi to map or unmap a drive
'* it would be nice if there was though
sHostServer = "server1"
sDestServer = "server2"
SourceFile = "C:\Filetotransfer.txt"
DestFile = "Z:\destination.txt"
Sharepath = "\\" & sDestServer & "\D$\scripting"
set oWMISvc = GetObject("winmgmts:\\" & sHostServer & "\root\cimv2")
'* Impersonation level must be delegation to map a drive using the privileges of the
'* account executing the script only supported in Win 2000 and above
oWMISvc.Security_.ImpersonationLevel = 4
set oFile = oWMISvc.Get("cim_datafile='" & SourceFile & "'")
set oProcess = oWMISvc.Get("Win32_Process")
'* map drive
lRet = oProcess.Create("net use Z: """ & Sharepath & """", Null, Null, lPID)
if lRet <> 0 then
wscript.Echo "Map Drive Failed Returned Code : " & lRet
wscript.quit(lRet)
end if
Wscript.Sleep 2000
'* copy file
lRet = oFile.Copy(DestFile)
if lRet <> 0 then
wscript.Echo "File Copy Failed Returned Code : " & lRet
end if
'* unmap drive
lRet = oProcess.Create("net use Z: /d /y", Null, Null, lPID)
if lRet <> 0 then
wscript.Echo "Remove map Drive Failed Returned Code : " & lRet
end if
Platforms
For online peer support, join
The Official Scripting Guys Forum!
To provide feedback or report bugs in sample scripts, please start a new discussion on the Discussions tab for this script.
Disclaimer
The sample scripts are not supported under any Microsoft standard support program or service. The sample scripts are provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.
Be the first to create a discussion.
|