运行命令行和来自VBS的命令 [英] Run Command Line & Command From VBS

查看:127
本文介绍了运行命令行和来自VBS的命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要运行一个命令,以使用vbs文件通过命令提示符将文件从一个位置复制到另一位置。

I need to run a command to copy a file from one location to another through Command Prompt using a vbs file. this is what I have however it keeps throwing an error at me.

'Dim oShell
Set oShell = WScript.CreateObject ("WScript.Shell")
oShell.run "cmd.exe /C copy "S:Claims\Sound.wav" "C:\WINDOWS\Media\Sound.wav"
Set oShell = Nothing'

我得到的错误是:

'Script: C:\******\command.vbs
Char: 30
Error: Expected end of statement
Code: 80040401

来源:Microsoft VBScript编译错误'

Source: Microsoft VBScript compilation error'

请帮助:)

推荐答案

问题在此行上:

oShell.run "cmd.exe /C copy "S:Claims\Sound.wav" "C:\WINDOWS\Media\Sound.wav"

您在 S:Claims旁边的第一个引号结束字符串;您需要使用第二个引号将文件周围的引号引起来,例如:

Your first quote next to "S:Claims" ends the string; you need to escape the quotes around your files with a second quote, like this:

oShell.run "cmd.exe /C copy ""S:\Claims\Sound.wav"" ""C:\WINDOWS\Media\Sound.wav"" "

您在 S:Claims\Sound.wav 中也有错字,应为 S: \Claims\Sound.wav

You also have a typo in S:Claims\Sound.wav, should be S:\Claims\Sound.wav.

我还假设 Set oShell = Nothing 之后也是错别字。

I also assume the apostrophe before Dim oShell and after Set oShell = Nothing are typos as well.

这篇关于运行命令行和来自VBS的命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆