I'm trying to get a specific file (which is in the current directory) to run in the background. To do this I am using batch script to make a file called file12.vbs , which will run file1.bat in the background. The problem is that file12.vbs isn't generating with all 3 lines of the code bellow. Does anyone know how to resolve this?

echo Set WshShell = CreateObject("WScript.Shell")>> file12.vbs
echo WshShell.Run chr(34) & "file1.bat" & Chr(34), 0>> file12.vbs
echo Set WshShell = Nothing>> file12.vbs`

Not able to generate new file properly with batch scripting

I was able to get it to work using this syntax using the caret ^ symbol to escape characters

IF EXIST file12.vbs DEL /Q /F file12.vbs
echo Set WshShell = CreateObject^("WScript.Shell"^)
echo WshShell.Run chr^(34^) ^& "file1.bat" ^& Chr^(34^), 0
echo Set WshShell = Nothing
)>> file12.vbs

Further Resources

  • 1
    That's a good point, I put IF EXIST logic up top for it to be deleted so if the OP needs it to be deleted first it will be before it's appended to. Additionally, you can just use > file12.vbs and remove the IF EXIST logic. I just left that part as it was per the example in the question. – Pimp Juice IT Mar 11 '17 at 18:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.