AidenTooMLG
AidenTooMLG

Reputation: 67

How can I convert this vbs into a batch file?

Here is the code:

Set sapi=Createobject("sapi.spvoice") sapi.Speak ("Preparing your file now...")

I want to insert it into a batch file with other codes in it. It would be something like this;

Start google chrome
Open a new command prompt tab
Go to stack overflow
*Set sapi=Createobject("sapi.spvoice")
sapi.Speak ("Please subscribe to AstralWolf")*

How can I make that code VBS - Batch?

Thanks!

Upvotes: 1

Views: 3542

Answers (3)

nxttym
nxttym

Reputation: 1

@echo off
cscript yourscript.vbs

Paste it into a batch, it will open it. To hide the VBS, right-click, properties, and check "Hidden". If you had it on, in Control Panel, untick "Show Hidden Icons".

Upvotes: 0

Hackoo
Hackoo

Reputation: 18827

You can try like that by the easy way when you call it as a function : Call:Speak "<your message goes here>"

@echo off
Start "" chrome.exe "www.stackoverflow.com"
Call:Speak "Please subscribe to AstralWolf"
exit /b
::**********************************************
:Speak <msg>
(
    echo Set sapi=Createobject("sapi.spvoice"^)
    echo sapi.Speak("%~1"^)
)>"%tmp%\%~n0.vbs"
Cscript /nologo "%tmp%\%~n0.vbs"
Del "%tmp%\%~n0.vbs"
exit /b
::**********************************************

Upvotes: 1

Pankaj Jaju
Pankaj Jaju

Reputation: 5471

A quick way to do it is to create a temp vbs file and run it from bat file. Sample batch file code would be something like the below

@echo off
cd %temp%
echo set varSAPI=WScript.CreateObject("sapi.spvoice") >> "tmp.vbs"
echo varSAPI.Speak "Please subscribe to AstralWolf" >> "tmp.vbs"
start tmp.vbs
pause
del tmp.vbs
@echo on
exit /b

Edit - As per @Ansgar Wiechers's suggestion, I am using temp folder.

Upvotes: 1

Related Questions