# Creating .vbs from .bat



## jfranks0 (May 8, 2007)

I am in the process of creating a batch file that will export a registry key to a text file, modify it, then import it back to the registry as a new string. The batch file will have to create 2 VBS scripts to call to which I'm having trouble with. For the most part the entire process works fine, but there are a few lines that I am unable to get to ECHO to the VBS file.

How can I get this command to successfully run from a .bat file? Let me know if you would like to see the entire script.

echo Wscript.Echo "Utility to copy Unicode text file to an ANSI text file." &_>>c:\witoansi.vbs

It should write the following line to c:\witoansi.vbs.
Wscript.Echo "Utility to copy Unicode text file to an ANSI text file." &_

Any help is appreciated.
jf


----------



## cristobal03 (Aug 5, 2005)

I don't know too much about batch scripting, but I doubt *echo* is the appropriate output method to append directly to another file. I bet the error message that generates is an unrecognized command/filename error. I'll take a look around and see if I can find anything.

chris.


----------



## cristobal03 (Aug 5, 2005)

[bump]

Hmmm...on second thought, it might be something as simple as lack of whitespace around the arrows. What happens when you do something like this?


```
echo Wscript.Echo "Utility to copy Unicode text file to an ANSI text file." &_ >> c:\witoansi.vbs
```
I guess what I'm really saying is, how does the current command behave, beyond failing at the append?

chris.


----------



## cristobal03 (Aug 5, 2005)

[bump 2]

Okay, testing something really simple points to the ampersand. I found a related thread here:

http://www.computing.net/programming/wwwboard/forum/12936.html​Sorry I took a convoluted route.

HTH

chris.


----------



## jfranks0 (May 8, 2007)

Thanks Chris.

I'll give the CHANGE command a try. Let's hope it works!!!

jf


----------



## Mosaic1 (Aug 17, 2001)

To do this, youhave to let the batch know that the ampersand is not to be seen as code to be run.

Adding a ^ before the & will get you a vbs looking like this:

```
Wscript.Echo "Utility to copy Unicode text file to an ANSI text file." &_
```
Here's your Batch:

```
echo Wscript.Echo "Utility to copy Unicode text file to an ANSI text file." ^&_ >>witoansi.vbs
```
Hope it helps.


----------



## cristobal03 (Aug 5, 2005)

I didn't realize the command line had an escape character.

Thanks for the tip :up:

chris.


----------



## Mosaic1 (Aug 17, 2001)

You're welcome.

For the Original Poster. The line you want to write to the vbs is going to generate an error.


----------

