制作一个创建特定 vbs 文件的批处理文件

making a batch file that creates a specific vbs file

我正在制作一个创建 vbs 脚本的批处理文件,该脚本发送键输入,但这似乎没有将“%”回显到脚本中。

echo set shell = createobject ("wscript.shell")> tempoary.vbs    
echo shell.SendKeys "%f" >> tempoary.vbs    
start tempoary.vbs

% 用于批处理文件中的变量,因此您的 batch 程序试图用它的值替换您的变量 %f。当然没有这个变量,所以你什么也得不到。

您应该能够转义 % 以便将其视为文字百分比:

echo shell.SendKeys "%%f" >> tempoary.vbs 

你应该这样写:

  1. 要转义像 ) 这样的特殊字符,您应该添加一个回车符 ^)
  2. 要转义像 % 这样的特殊字符,您应该添加 %%

进一步阅读: Escape Characters

@echo off
(
echo set shell = createobject ("wscript.shell"^)
echo shell.SendKeys "%%f" 
)> tempoary.vbs    
start "" tempoary.vbs