我如何使用 shell 脚本 运行 隐藏批处理文件?

How can i run a batch file hiddenly using shell script?

我正在处理 shell 脚本/.vbs 扩展文件,我想 运行 一个隐藏的批处理文件或在 shell 脚本的后台。我提到了我的代码,但它没有执行批处理文件。我已将文件保存为 test.vbs.

Set WshShell = CreateObject()
WshShell.Run chr(34) & "%USERPROFILE%\AppData\Local\RE.bat" & Chr(34), 0
Set WshShell = Nothing

提前致谢。

你需要 CreateObject("WScript.Shell"),而不是 CreateObject():

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run Chr(34) & "%USERPROFILE%\AppData\Local\RE.bat" & Chr(34), 0

否则VBScript 不知道你要创建什么!所以它不知道您想要具有 Run 方法的 shell 对象...

当你写CreateObject()时,你必须在那些圆括号中提及。您的代码看起来不错,只需像这样在圆括号中添加 WScript.shell

Set WshShell = CreateObject("WScript.shell")