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
218 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 84

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

830 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