10

I want to run a vbs command from command line as I would in batch calling

cmd.exe /c "echo.Hello World! & pause"

Obviously this doesn't work

wscript /C MsgBox("Hello world")

I could print the vbs and then call the temporary file and then delete it

cmd.exe /c "echo. [VBSCODE] > temp.vbs & wscript temp.vbs & del temp.vbs"

but this is too messy, and I don't want the prompt poping up.

3 Answers 3

21

This works directly on the command line:

mshta vbscript:Execute("MsgBox(""Message"",64,""Title"")(window.close)")

also for several commands:

mshta vbscript:Execute("MsgBox ""Message"",64,""Title"":MsgBox ""Hello again!"",64,""Hello"":close")
Sign up to request clarification or add additional context in comments.

5 Comments

Yes it sure does! At least on Win7 x64.
is there a way with w/csript ?
@Dexter: you could potentially run wscript ... from .hta itself. Eg. this works for me: mshta vbscript:Execute("CreateObject(""WScript.Shell"").Run(""wscript TEST.vbs""): close")
PS. Though the JScript-from-HTA launcher looks cleaner to my own eyes. Probably it's personal: mshta "javascript: new ActiveXObject( 'WScript.Shell' ).Run('wscript TEST.vbs'); close()"
PPS. On a second thought my answer does not seem to make sense, as it looks like you want to start the execution chain from 'wscript` itself but feed the code from cmd-line, and to avoid having it stoed on disk. I don't know the solution, so please excuse me.
2

VBScript requires a file for its source code. You want to specify stdin as the "file", but there is no mechanism to do that. So the answer is no - you cannot generate and run VBS code from the command line without using a temporary file.

Most people use a batch script to write temp VBS code, execute, and then delete the temp code, as PA has demonstrated.

I have discovered a mechanism to embed the VBS code within the batch file, without the need for a temporary file. But it is not very pretty. See Is it possible to embed and execute VBScript within a batch file without using a temporary file?

It is much cleaner to embed JScript within a batch file.

Comments

0

avoid typing over and over the same, just create a bat with the commands to run

sovb.bat

@echo off
echo %* >%temp%\temp.vbs
wscript %temp%\temp.vbs
del %temp%\temp.vbs

and then from the command line, invoke it

sovb MsgBox("Hello World")

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.