我遇到的错误是vbs在打开后没有将robocopy传递给cmd。我可以看到CMD窗口打开但它从未通过robocopy命令。请帮忙!
On Error Resume Next
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objRUN = CreatObject("wscript.shell")
If objFSO.FileExists("C:\Program Files\SAFARI Montage\SAFARI Montage Media Player\vlc-2.0.3\vlc.exe") Then
Set objFolder = objFSO.GetFile("C:\Program Files\SAFARI Montage\SAFARI Montage Media Player\vlc-2.0.3\vlc.exe")
MsgBox "Already Installed", 48, "32bit Search"
Set objFolder = Nothing
ElseIf objFSO.FileExists("C:\Program Files (x86)\SAFARI Montage\SAFARI Montage Media Player\vlc-2.0.3\vlc.exe") Then
Set objFolder = objFSO.GetFile("C:\Program Files (x86)\SAFARI Montage\SAFARI Montage Media Player\vlc-2.0.3\vlc.exe")
MsgBox "Already Installed", 48, "64bit Search"
Set objFolder = Nothing
ElseIf objFSO.FileExists("C:\Program Files (x86)\SAFARI Montage\SAFARI Montage Media Player\SAFARIMontageMediaPlayer.exe") Then
objRUN.run """CMD robocopy /E ""\\JERZYBOYSERVER\Shared Folders\Landing\vlc-2.0.3"" ""C:\Program Files (x86)\SAFARI Montage\SAFARI Montage Media Player\vlc-2.0.3""",1,true
Set objFolder = Nothing
Set objshell = Nothing
ElseIf objFSO.FileExists("C:\Program Files\SAFARI Montage\SAFARI Montage Media Player\SAFARIMontageMediaPlayer.exe") Then
objshell.Run """CMD robocopy /E ""\\JERZYBOYSERVER\Shared Folders\Landing\vlc-2.0.3"" ""C:\Program Files\SAFARI Montage\SAFARI Montage Media Player\vlc-2.0.3""",1,true
Set objFolder = Nothing
Set objshell = Nothing
Else MsgBox "VLC not installed properly", 16, "Failed"
End If
答案 0 :(得分:0)
在命令行的开头有太多双引号。变化
objRUN.run """CMD ...
到
objRUN.run "CMD ...
保留原来的其余部分。
更一般地说:从不在脚本中使用全局On Error Resume Next
。如果由于某种原因你必须使用错误处理,尽可能在本地执行,安装适当的错误处理例程,并在之后尽快禁用错误处理。
答案 1 :(得分:0)
您正在引用完整的cmd行。只需要引用已执行的命令
objshell.Run "CMD /c ""robocopy ""\\JERZYBOYSERVER\Shared Folders\Landing\vlc-2.0.3"" ""C:\Program Files\SAFARI Montage\SAFARI Montage Media Player\vlc-2.0.3"" /e "" ",1,true
但让Run
方法直接执行robocopy
objshell.Run "robocopy ""\\JERZYBOYSERVER\Shared Folders\Landing\vlc-2.0.3"" ""C:\Program Files\SAFARI Montage\SAFARI Montage Media Player\vlc-2.0.3"" /e ",1,true
答案 2 :(得分:0)
首先,从命令提示符运行此命令以确保它按预期工作:
robocopy /e "\\JERZYBOYSERVER\Shared Folders\Landing\vlc-2.0.3" "C:\Program Files (x86)\SAFARI Montage\SAFARI Montage Media Player\vlc-2.0.3"
如果是这样,只需将其转换为VBScript字符串即可。如果引号变得混乱,可能有助于逐步构建它。我没有使用引号,而是使用Chr(34)
来简化操作:
strCmd = "robocopy /e"
strCmd = strCmd & " "
strCmd = strCmd & Chr(34) & "\\JERZYBOYSERVER\Shared Folders\Landing\vlc-2.0.3" & Chr(34)
strCmd = strCmd & " "
strCmd = strCmd & Chr(34) & "C:\Program Files (x86)\SAFARI Montage\SAFARI Montage Media Player\vlc-2.0.3" & Chr(34)
您可能希望此时输出命令以确保它与您的第一个语句匹配。如果您正在使用CSCRIPT,则可以使用WScript.Echo
将命令字符串输出到控制台。如果您正在使用WSCRIPT,则可以使用InputBox
显示字符串,以便将其复制并粘贴到命令提示符。
WScript.Echo strCmd
' or
InputBox "", "", strCmd
如果看起来不错,请继续运行。
objShell.Run strCmd, 1, True