Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
785 views
in Technique[技术] by (71.8m points)

vbscript - Run Command Line & Command From 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:ClaimsSound.wav" "C:WINDOWSMediaSound.wav"
Set oShell = Nothing'

The error i get is:

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

Source: Microsoft VBScript compilation error'

Please help :)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The problem is on this line:

oShell.run "cmd.exe /C copy "S:ClaimsSound.wav" "C:WINDOWSMediaSound.wav"

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:ClaimsSound.wav"" ""C:WINDOWSMediaSound.wav"" "

You also have a typo in S:ClaimsSound.wav, should be S:ClaimsSound.wav.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...