How to run a cmd file using vbscript? [duplicate] - vbscript

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 :)

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.

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

Related

vbs text concatenation not working with wscript.arguments

I made a js script to convert text to speech and running a command line with vbs to keep the console window hidden. I am calling via a command so Im trying to use the parameters passed in to it.
I tried using the '+' operator like in most other languages but it didn't work, then I tried the '&' operator but to no success :(.
Set oShell = CreateObject ("Wscript.Shell")
Dim strArgs
strArgs = "cmd /c node audio.js" + WScript.Arguments.Item(0)
oShell.Run strArgs, 0, false
This
C:\Users\eh
type 56861329.vbs
WScript.Echo "cmd /c node audio.js" + WScript.Arguments.Item(0)
C:\Users\eh
cscript 56861329.vbs MissingSpace
cmd /c node audio.jsMissingSpace
should show the real problem. As #Geert said, & is the VBScript operator for concatenation and should be used.
I forgot a space I feel so dumb

How to run below command from vbscript

I have written vbscript code to set classpath of putty from command prompt
Dim oShell
putty_path="setx path %path%;C:\putty"
Set oShell = WScript.CreateObject ("WScript.Shell")
oShell.run "cmd /K" & putty_path
Set oShell = Nothing
When i execute vbscript code i am getting below error in command prompt
ERROR: Invalid syntax. Default option is not allowed more than '2' time(s).
Type "SETX /?" for usage. Please help
Because it has already worked, so it can't do it a second or subsequent time as it worked the first time. Just ignore.
Plus it's unnecessary what you are doing, just shell to PuTTY (you don't even need to use the extension).
oShell.run "putty"

Run external command silently

I am trying to run cmd code from vbscript (vbs file) silently.
I have tried this, but it doesnt hide the cmd window.
Dim oShell
Set oShell = WScript.CreateObject ("WScript.Shell")
oShell.run "cmd.exe /K ping example.org"
Set oShell = Nothing
What is the correct way to do that ?
Dim oShell
Set oShell = WScript.CreateObject ("WScript.Shell")
oShell.run "cmd.exe ping example.org",0,True
Set oShell = Nothing
As per the MSDN for .Run you can use the optional parameter for intWindowStyle, which will hide most windows from the screen, by setting it to 0. The True is to tell the operation to wait until completion before completing the script. That is of course optional.
If you hide the window you need to remove /K or else the script will never complete.

Deleting Winzip Command Line Add On 2.2 vbs

I'm trying to delete a file like winzip command line using this code
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFile("C:\Program Files\WinZip\wzuninst.exe wzcline C:\Program Files\WinZip\wzclun.dll")
When I run it on cmd it says Bad name or number. Can someone clarify it for me?
That's not a valid command line.
If you want to run a program you use wshshell.run.
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "cmd /k dir c:\windows\*.*"

how to call more than 1 batch files in a vbscript?

I am using the following code to call a batch file:
dim shell
set shell=createobject("wscript.shell")
shell.run "a.bat D:\a"
set shell=nothing
How do I call more than 1 batch file, so that when the 1st file's execution is over the 2nd file is executed.
as always, I really appreciate any help offered.
Below
shell.run "a.bat D:\a"
add another line with another
shell.run "b.bat ...."
Or create a batch file that calls all the other batch files, and call that batch file from your script.
Option explicit
Dim oShell
set oShell = Wscript.CreateObject("WScript.Shell")
oShell.Run "RunAs /noprofile /user:Admininistrator ""%comspec% /c 1stcommand && 2ndcommand && 3rdcommand""", 1, false
WScript.Sleep 1000
oShell.Sendkeys "AdmininistratorPassword~"
Wscript.Quit

Resources