繁体   English   中英

wshShell.Exec错误80070002“系统找不到指定的文件”

[英]wshShell.Exec Error 80070002 “The system cannot find the file specified”

我正在尝试使用wshShell.Exec或wshShell.Run通过另一个脚本运行一个脚本。 我已经尝试了两种方法,并且两种方法都给我相同的错误。 我已经用Google搜索了该问题,但找不到能解决该问题的任何东西。 真正真正相关的唯一建议是尝试使用wshShell.Run而不是Exec。

这是我脚本的相关部分:

strScriptPath = "T:\IT resources\Scripts\Shutdown Scripts"
strForceShutdown = "ForceShutdown.vbs"

  For j = 0 to 99
   Set objActive = wshShell.Run(strForceShutdown)
   ' In case I ever need to get this working to run it from another folder. 
   ' Set objActive = wshShell.Exec("cd " & strScriptPath & "")
   ' Set objActive = wshShell.Exec("wscript " & strForceShutdown & "") 
    constConf = MsgBox("Automatic shutdown initializing. Continue?" & chr(10) & "Y=Shutdown N=Postpone 30 minutes",4,"Automatic Shutdown Notification")

     If constConf = 7 Then
      objActive.Terminate
      Wscript.Sleep(1800000)

      Else
       objActive.Terminate
       Exit For
     End If
   Next

谢谢你的帮助!

Shell.Run 返回一个整数 ,因此您不能在其返回值上调用方法( Terminate )。 您也不可以Set它,因为它不是对象。

您可以通过运行关闭脚本来调用它。 给它完整的路径,但是,不要相对的路径。 从Task Scheduler启动的脚本通常具有与手动启动的脚本不同的“启动文件夹”,因此不必依赖您的脚本来相对地找到另一个。 同样,您必须在路径前面和后面添加Chr(34)来计算任何空格。

strForceShutdown = "c:\path\to\ForceShutdown.vbs"
wshShell.Run Chr(34) & strForceShutdown & Chr(34)

最后,为什么启动脚本然后询问是否关闭? 为什么不只是在用户响应后启动脚本,然后您就不必担心终止正在运行的进程。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM