Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
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
Medium Priority
?
235 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 85

Accepted Solution

by:
oBdA earned 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
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.
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 …
Suggested Courses

730 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