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
211 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 82

Accepted Solution

by:
oBdA earned 500 total points
Comment Utility
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
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

771 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

12 Experts available now in Live!

Get 1:1 Help Now