How Can I Transfer a File Using Remote Desktop Con

2020-08-01 05:38发布

I've spent the better part of the afternoon trying to figure this out. I have to upload a file to a connected computer via Remote Desktop Connection using a Script Written in VBSCript. I was going to use FTP, but found out that I can't.

Right now I have

Set fso = CreateObject("Scripting.FileSystemObject")
fso.CopyFile "C:\blahdiddyblah\blahdiddy.zip", "fubar.networkname.blah.com\directory

When I run this I get a bad login or password error I understand this is because it doesn't give me a way to login to remote desktop before it tries the upload.

I've tried something something similar to what's below, except with the password included as part of the string, in that case it throws a "path not found" error.

Option Explicit
Dim sComputer, sUsername
sComputer = InputBox("Please enter the Computer Name or IP")
sUsername = InputBox("Please Enter the Users Login ID")

Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
fso.CopyFile "\\servername\path\servers.lst" _
   , "\\" & sComputer & "\c$\Documents and Settings\" & sUsername & "\Local Settings

标签: vbscript
1条回答
Anthone
2楼-- · 2020-08-01 06:26

OK, so what I've done here is use the net use command from windows which makes the Remote Desktop Connection, and basically wrap it in VBScript.

Set WshShell = CreateObject("WScript.Shell")

WshShell.Run("net use \\destinationServerAddress /user:domain\UserName PW")

//Allow Sleep while connection is made, otherwise it will fail because it has not had the opportunity to login yet.

WScript.Sleep 20000



Set fso = CreateObject("Scripting.FileSystemObject")

//Make sure you have admin rights for the folder, and it is shared. This means right click, and going into Sharing Options in windows.

fso.CopyFolder "SourceFldr", "\\ServerFolder/Fubar", true
查看更多
登录 后发表回答