1

当我使用批处理文件创建文件invisible.vbs然后删除时,它会因错误而停止。基本上,我想做的是让批处理文件制作这个文件。

这是我运行批处理文件时遇到的错误:

C:\Users\HP\Desktop>"New Text Document.bat"
 CreateObject("Wscript.Shell").Run """"
'WScript.Arguments' is not recognized as an internal or external command, operable program or batch file.
'""""' is not recognized as an internal or external command, operable program or batch file.

这是批处理文件中的内容:

@ECHO OFF  
CD /D %~dp0  
ECHO\ CreateObject("Wscript.Shell").Run """" & WScript.Arguments(0) & """", 0,False>>Invisible.vbs  
::What I want to do with the file is here  
DEL %CD%\invisible.vbs /Q /S

我注意到该文件已生成,但它是空的,因此当我尝试使用它使另一个批处理文件不可见时什么也不做。

4

1 回答 1

2

这是由&echo 语句中的符号引起的。^在字面上使用它时需要通过批处理转义字符进行转义^&。您可能还想使用单输出重定向运算符>(覆盖现有)而不是双>>(附加到现有)。

@ECHO OFF
CD /D %~dp0
ECHO.CreateObject^("Wscript.Shell"^).Run """" ^& WScript.Arguments^(0^) ^& """", 0,False>Invisible.vbs
::What I want to do with the file is here  
DEL %CD%\invisible.vbs /Q /S

另一个技巧是%TEMP%在创建丢弃文件时使用目录变量。

于 2012-12-10T21:52:11.123 回答