Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8808469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:37:51+00:00 2026-06-14T02:37:51+00:00

I have this batch file: @echo off echo StrText=Application created Successfully > spk.vbs echo

  • 0

I have this batch file:

@echo off
echo StrText="Application created Successfully" > spk.vbs
echo set ObjVoice=CreateObject("SAPI.SpVoice") >> spk.vbs
echo ObjVoice.Speak StrText >> spk.vbs
start spk.vbs

This batch file creates spk.vbs in the same directory and outputs the text “Application created Successfully” with the computer voice.

Now I want the batch file to speak out the content of a text file given to it on the command line instead (%1). And the spk.vbs file should be created in the default Windows temporary directory instead. How can I do this?

***Edit 06.11.2012 20:24

Meanwhile I’ve discarded the idea of using a batch file script to generate a vbs script file and want to use the vbs script directly. Although I am an absolute beginner with VBS I created this one:

Set objFSO = CreateObject("Scripting.FileSystemObject")
strAFile = Wscript.Arguments(0)
Set objFile = objFSO.GetFile(strAFile)
If objFile.Size > 0 Then
  Set objReadFile = objFSO.OpenTextFile(Wscript.Arguments(0), 1)
  strContents = objReadFile.ReadAll 
  objReadFile.Close
  set ObjVoice=CreateObject("SAPI.SpVoice") 
  ObjVoice.Speak strContents 
Else
  Wscript.Echo "The file is empty."
End If

It works, but probaly I’ve made a lot of mistakes. Can someone tell me how the vbs script can be optimized? Thank you!

***Edit 06.11.2012 22:19

After this worked a few times, now it does not work anymore: Now the computer speaker outputs only “Y” and the first character of the text file! Has this something to do with an error in my script?

***Edit 10.11.2012 19:32
Found the bug: The above script work only with ANSI-coded text-files. It does not work with UNICODE text-files! Why? How can I make it work with UNICODE text-files too?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T02:37:53+00:00Added an answer on June 14, 2026 at 2:37 am

    Use the 4th parameter of the .OpenTextFile (or the 2nd parameter of the .OpenAsTextStream) method to specify whether to open the file as ASCII or Unicode (16).

    I don’t find any serious mistakes in your code snippet, but perhaps you want to consider:

    1. using “Option Explicit” (explicitly)
    2. checking whether the user passed at least one argument to the script
    3. avoiding to refer to the same ‘object’ via different names/variables (strAFile, WScript.Arguments(0))
    4. using .OpenAsTextStream as you have a File object already
    5. avoiding ‘magic numbers’ (e.g. 1) by defining the appropriate constants (e.g. ForReading)
    6. avoiding unnecessary variables (code you don’t write can’t be wrong)

    E.g:

    Set objReadFile = objFSO.OpenTextFile(WScript.Arguments(0), 1)
    strContents = objReadFile.ReadAll 
    objReadFile.Close
    

    ==>

    Const cnUnicode = -1
    ...
    strContents = objFile.OpenAsTextStream(ForReading, cnUnicode).ReadAll()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this in a batch file called find_java.bat: @echo off for /f delims=
I have a simple batch file like this: echo off taskkill /im test.exe /f
I have this batch file @ECHO OFF ECHO Please Enter Path of the View,
I have a for loop in a batch file: @echo off set logpath1=C:\path\to\first\log set
I have a batch script that looks like this: Test.bat @echo off :: Starts
I have a batch file using the following code: @echo off :: BatchGotAdmin :-------------------------------------
I have this simple little batch file program that I wrote but it fails
I have a batch file and I need to invoke it like this mybatch.bat
Can someone help me with this one? I have a batch file, where I
@echo off start /wait notepad start worpad This is the code i have written

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.