0

I want to save this code from batch file to txt but cant. I write this code but this code not working, cant save the address how can i save "some code" like this from batch file to txt. i have many codes and need to save it at the right time from batch file to txt and not execute them just save as txt. tnq

this code want to save:

Set WshShell = CreateObject("WScript.Shell") 
WshShell.Run chr(34) & "C:\Program Files\Windows Task\WindowsTask.bat" & Chr(34), 0
Set WshShell = Nothing

this is my solution and not working:

@echo off
(echo Set WshShell = CreateObject^("WScript.Shell"^) )> sina.txt
(echo WshShell.Run chr^(34^) & "C:\Program Files\Windows Task\WindowsTask.bat" & Chr^(34^), 0)  >> sina.txt
(echo Set WshShell = Nothing) >> sina.txt
pause
Sina
  • 11
  • 1
  • 1
    check answers here : https://stackoverflow.com/questions/9074476/is-it-possible-to-embed-and-execute-vbscript-within-a-batch-file-without-using-a for a more effective ways to embed a vbscript code into a batch file. – npocmaka Feb 01 '22 at 13:53

2 Answers2

1

You have far less trouble with paranthesis and escaping if you put the redirection at the beginning of the line.

@echo off
>  sina.txt echo Set WshShell = CreateObject("WScript.Shell") 
>> sina.txt echo WshShell.Run chr(34) ^& "C:\Program Files\Windows Task\WindowsTask.bat" ^& Chr(34), 0
>> sina.txt echo Set WshShell = Nothing
pause
ooLi
  • 63
  • 6
1

You need to double the %.

>> sina2.txt echo SET TodayYear=%%DATE:~10,4%%

The result in your file will be:

SET TodayYear=%DATE:~10,4%
ooLi
  • 63
  • 6