Solved

How to create an *.bat or *.vbs script which output is a new file with extension *.vbs (another script) ??

Posted on 2015-02-23
2
215 Views
Last Modified: 2015-02-24
I need a script (*.bat or *.vbs) that when executed it will create another script file with extension *.vbs

In summary, the main objective of the script is to create another script with extension *.vbs.
0
Comment
Question by:acunaara
2 Comments
 
LVL 83

Accepted Solution

by:
oBdA earned 500 total points
ID: 40627611
The best way depends on what it is exactly that you want to do.
One way would be like this; it has a combination of dynamic building with batch environment variables (%BatchScript%), and a passed argument.
Note that "&" will have to be escaped with "^":
@echo off
setlocal
set VBScript=C:\Temp\VBScript.vbs
set VBArgument=Some Argument
set BatchScript=%~nx0
if exist "%VBScript%" del "%VBScript%"
>>"%VBScript%" echo Wscript.Echo "Hello, I'm the VBScript called from '%BatchScript%'; the argument passed to me was '" ^& WScript.Arguments(0) ^& "'"
>>"%VBScript%" echo Wscript.Echo "Done with the VB script."
cscript.exe /nologo "%VBScript%" "%VBArgument%"
del "%VBScript%"
echo Done with the batch script.

Open in new window

0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 40627672
You already have your answer, but just to add.. you can also do it one go without the redirects on each line if easier... like oBdA says 'it depends' what you want, if it is dynamic, or a static script etc.

@echo off
(echo wscript.echo "Whatever"
echo Msgbox "something"
) > myscript.vbs

Other examples on my site here e.g. this one makes a temporary VBScript file to prompt for a folder in a batch file:

http://scripts.dragon-it.co.uk/links/batch-gui-folder-mk2

Steve
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now