Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:Claims\Sound.wav" "C:\WINDOWS\Media\Sound.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 :)

like image 509
user1590368 Avatar asked Apr 18 '13 15:04

user1590368


People also ask

What is the Run command in Command Prompt?

The Run command on an operating system such as Microsoft Windows and Unix-like systems is used to directly open an application or document whose path is known.

How do I Run a Command Prompt in terminal?

Open Command Prompt in WindowsClick Start and search for "Command Prompt." Alternatively, you can also access the command prompt by pressing Ctrl + r on your keyboard, type "cmd" and then click OK.


2 Answers

The problem is on this line:

oShell.run "cmd.exe /C copy "S:Claims\Sound.wav" "C:\WINDOWS\Media\Sound.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:\Claims\Sound.wav"" ""C:\WINDOWS\Media\Sound.wav"" "

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

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

like image 106
LittleBobbyTables - Au Revoir Avatar answered Oct 07 '22 18:10

LittleBobbyTables - Au Revoir


Set oShell = CreateObject ("WScript.Shell") 
oShell.run "cmd.exe /C copy ""S:Claims\Sound.wav"" ""C:\WINDOWS\Media\Sound.wav"" "
like image 39
Shahriar Khazaei Avatar answered Oct 07 '22 18:10

Shahriar Khazaei