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
219 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 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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The viewer will learn how to count occurrences of each item in an array.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

752 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