VBScript 80004005;按计划工作了好几个小时,突然就不行了

VBScript 80004005;按计划工作了好几个小时,突然就不行了,vbscript,Vbscript,我不熟悉VBScript。对于任何错误或缺少必要信息,我深表歉意。我会尽我最大的努力,尽我所能帮助你帮助我 我的问题是,当我执行脚本时,会出现以下错误: 电话号码:22 字符:5 错误:未指定的错误 代码:80004005 来源:(空) 奇怪的是,我一整天都在运行同一个脚本多次,没有任何问题。现在,当我运行它时,会显示错误。脚本中没有任何更改。我尝试过重新启动,但似乎没有任何效果 代码如下: Call Main Function Main Dim IE Dim pin Set IE = W

我不熟悉VBScript。对于任何错误或缺少必要信息,我深表歉意。我会尽我最大的努力,尽我所能帮助你帮助我

我的问题是,当我执行脚本时,会出现以下错误:

  • 电话号码:22
  • 字符:5
  • 错误:未指定的错误
  • 代码:80004005
  • 来源:(空)
奇怪的是,我一整天都在运行同一个脚本多次,没有任何问题。现在,当我运行它时,会显示错误。脚本中没有任何更改。我尝试过重新启动,但似乎没有任何效果

代码如下:

Call Main

Function Main
Dim IE
Dim pin
Set IE = WScript.CreateObject("InternetExplorer.Application", "IE_")
Set objShellApp = CreateObject("Shell.Application")
Set IE2 = WScript.CreateObject("InternetExplorer.Application", "IE_")

pin=inputbox("Pin: ","Enter the pin to continue","")

IE.Visible = True
IE.Navigate "https://ps.hasdk12.org/admin/pw.html"

For Each objWindow in objShellApp.Windows
If LCase(objWindow.LocationName) = LCase("PowerSchool") Then
  Set IE2 = objWindow
End If
WScript.Sleep (5)
Next

With IE2.Document
    .getElementByID("fieldPassword").value = "username;" + pin
    .getElementByID("btnEnter").click
End With

For Each objWindow in objShellApp.Windows
If LCase(objWindow.LocationName) = LCase("Start Page") Then
  Set IE2 = objWindow
End If
WScript.Sleep (5)
Next

End Function

脚本出错的最可能原因是页面加载时间的变化,或者打开的Shell资源管理器和IE窗口的数量等。所有问题都是因为脚本在IE加载页面时没有等待,它会检查每个资源管理器窗口,即使找不到目标窗口也会继续

请尝试以下代码:

Call Main

Function Main()
    Dim oIE
    Dim sPin
    Set oIE = WScript.CreateObject("InternetExplorer.Application", "IE_")
    sPin = InputBox("pin: ","Enter the pin to continue", "")
    oIE.Visible = True
    oIE.Navigate "https://ps.hasdk12.org/admin/pw.html"
    WaitIE oIE, "PowerSchool"
    With oIE.Document
        .getElementByID("fieldPassword").value = "username;" + sPin
        .getElementByID("btnEnter").click
    End With
    WaitIE oIE, "PowerSchool"
End Function

Function WaitIE(oIE, sLocation)
    Do Until (LCase(oIE.LocationName) = LCase(sLocation)) And (Not oIE.Busy) And (oIE.ReadyState = 4)
        WScript.Sleep 5
    Loop
End Function

我删除了第二个IE变量,为什么您通过
objShellApp.Windows
获取IE2?也许我错过了什么。。?在我看来,你已经有了IE实例,因此不需要以这种方式获得相同的实例,只需控制你拥有的实例即可。此外,我还添加了单独的函数,等待IE完成页面加载

原始代码不等待的原因是,由于某种原因,导航完成后实例丢失。你可以阅读更多关于它的信息(似乎这是Windows7+的问题)IE2实例是因为我是一个noob:)现在我很清楚了,一旦我为类似的问题提出了解决方案,请参阅。