0

I was making a batch file that was able to create a vbs coded file I had already made but when I tried running the file it kept trying to run the vbs code as a command and not put it in the file the code that gave the errors are

set line5=set objWMIService = getobject("winmgmts://"_& strComputer & "/root/cimv2")
echo %line5% >>password.vbs

this one tried to run the strComputer as a command

set line20=strComputer = "."
echo %line20% >>password.vbs

this one tried to run the strComputer part but I have one like that and it works just fine

set line21=strExe = "explorer.exe"
echo %line21% >>password.vbs

in this one it is trying to load the strEXE as a command

set line49=WScript.echo "Created: " & strExe & " on " & strComputer
echo %line49% >>password.vbs

for this last one the program is trying to run " on " as the command

So if anyone reading does not understand my problem I will say it again what I am trying to do is save the vbs code into a file but the batch window keeps on trying to execute random commands that I am trying to put in the file which makes it not put them in and give me errors making the file not work correctly I am going to say this in advance thank you to anyone who tries to help

Flame923
  • 1
  • 1
  • see [this](http://stackoverflow.com/questions/8055371/how-to-run-two-commands-in-one-line-in-windows-cmd) – jan.supol Jul 08 '16 at 05:48
  • may be it will be better to check [this](http://stackoverflow.com/a/9074483/388389) instead of creating a separate vbscript file. – npocmaka Jul 08 '16 at 05:48
  • also check [this](http://stackoverflow.com/a/36679829/2152082) (it's for generating a second batchfile, but the technique is the same) – Stephan Jul 08 '16 at 05:54

1 Answers1

0

try this:

@echo off
cls
set line1=FirstLineOfCodeHere
set line2=SecondLineOfCodeHere
(echo %line1%
echo %line2%)>filename.vbs

UPDATE: Use '>' to overwrite the file. Use '>>' to write more on the original file.