VBS:oShell.run 和 robocopy 不工作

VBS: oShell.run and robocopy not working

我正在尝试使用 VBS 和 robocopy 将共享镜像到本地计算机。该脚本有效,但共享文件夹的路径中有空格,我无法让它与带空格的路径一起使用。

InputFile = "\baardrob\Software application\Scripts\Input\computers.Txt"
Const OverWriteFiles = True
Set oShell = WScript.CreateObject("WSCript.shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(InputFile)
Set myLog = objFSO.OpenTextFile("\baardrob\Software application\Scripts\Input\failed.txt", 2)
Do Until objFile.AtEndOfStream
  strComputer = objFile.ReadLine
  On Error Resume Next
  oShell.run "robocopy "\baardrob\software application" c:\temps /mir"  
  If Err Then myLog.WriteLine strComputer
  On Error Goto 0
Loop
myLog.Close

MsgBox "Done"

编辑: Ekkehard.Horner 解决方案有效,但我还有另一个问题。 c:\temps 只是试图让它工作,它实际上应该写入“\”和 strComputer“\c$”,但这不起作用。

我已经试过了:

InputFile = "\baardrob\Software application\Scripts\Input\computers.Txt"
Const OverWriteFiles = True
Set oShell = WScript.CreateObject("WSCript.shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(InputFile)
Set myLog = objFSO.OpenTextFile("\baardrob\Software application\Scripts\Input\failed.txt", 2)
Do Until objFile.AtEndOfStream
  strComputer = objFile.ReadLine
  On Error Resume Next
  oShell.run "robocopy ""\baardrob\Software application""  ""\"" & strComputer & ""\c$"" /mir" 
  If Err Then myLog.WriteLine strComputer
  On Error Goto 0
Loop
myLog.Close

MsgBox "Done"

你的

"robocopy "\baardrob\software application" c:\temps /mir" 

不是有效的 VBScript:

>> s = "robocopy "\baardrob\software application" c:\temps /mir"
>>
Error Number:       1002
Error Description:  Syntax error

通过使用 "" 转义来修复 'inner' 引号(参见 ):

>> s = "robocopy ""\baardrob\software application"" c:\temps /mir"
>> WScript.Echo s
>>
robocopy "\baardrob\software application" c:\temps /mir

更新扩充问题:

>> strComputer = "pipapo"
>> s = "robocopy ""\baardrob\Software application""  ""\"" & strComputer & ""\c$"" /mir"
>> WScript.Echo s
>>
robocopy "\baardrob\Software application"  "\" & strComputer & "\c$" /mir
>> s = "robocopy ""\baardrob\Software application""  ""\" & strComputer & "\c$"" /mir"
>> WScript.Echo s
>>
robocopy "\baardrob\Software application"  "\pipapo\c$" /mir