gpt4 book ai didi

windows - 为什么没有关于错误 80070002 的说明?

转载 作者:可可西里 更新时间:2023-11-01 10:19:22 26 4
gpt4 key购买 nike

我不小心尝试从一些 Visual Basic 脚本启动一个不存在的程序:

Dim WshShell
Set WshShell = CreateObject("Wscript.Shell")
On Error Resume Next
WshShell.Run "incorrect"
WScript.Echo "Error:" & vbTab & Err.Description & vbCrLf & _
"Code:" & vbTab & Hex(Err.Number)

这给出了:

Error:  Code:   80070002

所以没有描述

当我禁用错误检查(注释掉 On Error Resume Next)时,我确实得到了描述:

---------------------------Windows Script Host---------------------------Script: D:\Folder\MyScript.vbsLine:   3Char:   1Error:  The system cannot find the file specified. Code:   80070002Source:     (null)---------------------------OK   ---------------------------

这种行为差异是错误吗?或者我错过了什么?我在任何地方都找不到这个记录。

最佳答案

我自己做了一些测试,它似乎只发生在 WshShell.Run() 中。例如,尝试以下代码,其工作方式相同,但请注意输出。

Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
On Error Resume Next
'This line will fail because there is no Type of 88.
WshShell.LogEvent 88, "incorrect"
WScript.Echo "Error:" & vbTab & Err.Description & vbCrLf & _
"Code:" & vbTab & Hex(Err.Number)

输出(On Error Resume Next):

Error:  Invalid procedure call or argumentCode:   5

Output (without On Error Resume Next):

Error:  Invalid procedure call or argumentCode:   5

My guess is that WshShell.Run() is only reading from StdOut and not StdErr when On Error Resume Next is used, this is unique to WshShell.Run() because it is attempting to create a new process.

You could take this further by perhaps testing using WshShell.Exec() which gives access to both output streams.

Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
On Error Resume Next
Set WshExec = WshShell.Exec("incorrect")
WScript.Echo "Error:" & vbTab & Err.Description & vbCrLf & _
"Code:" & vbTab & Hex(Err.Number)

奇怪地检查了 WshExec.StdOutWshExec.StdErr,两者都不包含错误输出,但该方法在 On Error Resume Next 时按预期运行> 被使用。

所以绝不是结论性的。

但是作为accompanying article州;

Just remember, scripting without mysteries would be insipid and boring


有用的链接

关于windows - 为什么没有关于错误 80070002 的说明?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33149138/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com