获取“找不到文件”错误

时间:2014-07-30 18:25:47

标签: vbscript

我不明白为什么这段代码:

Set oWMP = CreateObject("WMPlayer.OCX.7")
Set oCMD = CreateObject("WScript.Shell")

Sub OpenFile(file)
  oCMD.run file
End Sub

Sub OpenCMD
  oCMD.run "%COMAPEC% /c start cmd"
End Sub

Sub Blink
  oCMD.run "%COMAPEC% /c exit"
End Sub

Sub Wait(seconds)
  oCMD.run "%COMSPEC% /c ping -n " & seconds+1 & " 127.0.0.1", 0, True
End Sub

Sub PromptCommand(command)
  oCMD.run "%COMAPEC% /c " & command
End Sub

Blink
Wait("0.5")
OpenCMD
Wait("7")
OpenFile("C:\Documents and Settings\Scott\Desktop\Lemmings\LEMMINGS.bat")

给了我以下错误:

enter image description here

2 个答案:

答案 0 :(得分:1)

首先引用传递给.Run的命令行:

oCMD.run """" & file & """""

而不是:

oCMD.run file

(参见this

答案 1 :(得分:1)

第13行

oCMD.run "%COMAPEC% /c exit"

我怀疑你错误地输入了环境变量。使用%COMAPEC%替换脚本中每次出现的%COMSPEC%

当然,始终在双引号之间放置路径,建议使用@Ekkehard.Horner。您可以使用如下引用函数来简化处理:

Function qq(str) : qq = Chr(34) & str & Chr(34) : End Function

oCMD.Run qq(file)

比一串字符串连接更易读。

相关问题