批量内容:
echo Set wshShell =wscript.CreateObject("WScript.Shell")>"C:\Users\Riccardo\Desktop\prova.vbs"
<nul set /p =wshshell.sendkeys ^"^<nul set ^/p ^=>>"C:\Users\Riccardo\Desktop\prova.vbs"
Type "C:\Users\Riccardo\Desktop\prova.txt">>"C:\Users\Riccardo\Desktop\prova.vbs"
echo {bs}^>^"^"C:\Users\Riccardo\Desktop\prova.txt^"^"{enter}^">>"C:\Users\Riccardo\Desktop\prova.vbs"
wscript "C:\Users\Riccardo\Desktop\prova.vbs"
生成的vbs是:
Set wshShell =wscript.CreateObject("WScript.Shell")
wshshell.sendkeys "<nul set /p =La#{bs}>""C:\Users\Riccardo\Desktop\prova.txt""{enter}"
prova.txt包含:
La#
从新的命令提示符会话执行此行:
wscript "C:\Users\Riccardo\Desktop\prova.vbs"
prova.txt变为
La
但是如果从批处理执行与上面相同的行:
wscript "C:\Users\Riccardo\Desktop\prova.vbs"
没有任何反应!
我该如何解决问题?
答案 0 :(得分:0)
尝试像这样调用脚本:
C:\Users\Riccardo\Desktop\prova.vbs
如果这不起作用,请将目录更改为桌面,然后调用vbs
:
cd C:\Users\Riccardo\Desktop\
prova.vbs
这应该在批处理文件中起作用。
答案 1 :(得分:0)
我解决了我的问题。 &#34; Prova.bat&#34;代码是:
echo Set wshShell =wscript.CreateObject("WScript.Shell")>prova.vbs
echo wshShell.Run "cmd">>prova.vbs
echo WScript.Sleep 250>>prova.vbs
<nul set /p =wshShell.sendkeys ^"^<nul set ^/p ^=>>prova.vbs
Type prova.txt>>prova.vbs
<nul set /p ={bs}^>prova.txt{enter}exit{enter}^">>prova.vbs
wscript prova.vbs
DEL /q prova.vbs 2> NUL
&#34; Prova.vbs&#34;生成和删除的是:
Set wshShell =wscript.CreateObject("WScript.Shell")
wshShell.Run "cmd"
WScript.Sleep 250
wshShell.sendkeys "<nul set /p =La#8{bs}>prova.txt{enter}exit{enter}"
&#34; Prova.txt&#34;之前:
La#8
&#34; Prova.txt&#34;现在:
La#
我找到了使用bat + vbs文件在txt文件中插入退格符的方法! ;-)我希望这样的解决方案可以帮助其他人。