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"
Related
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
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"" "
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.
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\*.*"
Do you think of any reason that this line should crash:
Set oShell = WScript.CreateObject ("WScript.Shell")
... only if I launch the script from InstallShieldExpress as a custom-action.
MsgBox "before create ObjectShell"
Set oShell = WScript.CreateObject ("WScript.Shell")
MsgBox "after create ObjectShell"
I never see the "after create ObjectShell" message ;-(
and if I simply launch the script by double-clicking on the script file in a windows explorer, of course everything is ok.
It may be that the global WScript object isn't available in the InstallShield environment. You can check this using a script like this:
MsgBox Not IsEmpty(WScript) ' True if WScript is defined, False if it's undefined
If WScript is undefined, try using CreateObject("WScript.Shell") instead. See also What is the difference between CreateObject and Wscript.CreateObject?