【发布时间】:2016-06-01 08:51:28
【问题描述】:
我对 VBScript 有一个非常奇怪的问题:它可以正常工作,具体取决于 Web 所在的服务器。
我在两台装有 IIS 7.5 的服务器上拥有相同的 Web 应用程序。在每台服务器中,代码完全相同相同。
VBScript 执行一些 Excel 行并更新 Web 应用程序中的一些信息。更新此信息时出现问题。在其中一台服务器中,没有问题,但在另一台服务器中,我收到以下错误:
脚本运行正常,我猜没有语法错误
抛出错误的代码是:
With objIE
If (testing) Then
.Navigate URLtesting
Else
.Navigate URL
WScript.Sleep 2000
End If
WaitWebLoad()
.document.getElementById(user).Value = userScript
.document.getElementById(password).Value = passwordScript
.document.getElementById(logInButton).Click()
WaitWebLoad()
.document.getElementByID(loretoLink).Click()
WaitWebLoad()
.document.getElementByID(updatePLLink).Click()
WaitWebLoad()
Do
lastRow = activeSheet.Cells(rowIndex, columnPL_ID).Value
dateAssociated = activeSheet.Cells(rowIndex, columnArrivalDate).Value
concesion = activeSheet.Cells(rowIndex, columnConcesion).Value
If lastRow <> "" Then
.document.getElementByID(searchPL_TB).Value = lastRow
.document.getElementByID(searchPL_Button).Click()
WaitWebLoad()
If (Not (.document.getElementByID(errorLookingPL)) Is Nothing Or Not (.document.getElementByID(noSearchResult) Is Nothing)) Then
'PL not found
recordsNotFound = recordsNotFound + 1
WriteOpenFileText(logFilePath), (Now & vbTab & "***PL not found: " & lastRow & " - [" & dateAssociated & "]" & " - " & concesion & vbCrLf)
Else ...
第295行是:
If (Not (.document.getElementByID(errorLookingPL)) is Nothing Or Not (.document.getElementByID(noSearchResult) is Nothing)) Then
WaitWebLoad函数代码为:
Function WaitWebLoad()
Dim timer
timer = 0
With objIE
Do While .Busy
If timer < timerWebLoad Then
WScript.Sleep 100
timer = 100
Else
'Error loading the web
objExcel.Workbooks.close
objExcel.quit
objIE.quit
DeleteFile(pathTemp)
endScriptStamp = Now
WScript.Echo("Error." & vbCrLf & "Total runtime is: " & DateDiff("s", startScriptStamp, endScriptStamp) & " seconds.")
WScript.quit
End If
Loop
End With
End Function
我猜问题是脚本在运行发生错误的服务器时丢失了objIE 对象,但我不知道为什么它只在其中一台服务器中丢失。
【问题讨论】:
-
我不确定 IIS 与此有什么关系,您正在运行的 VBS 代码是客户端 (此实例中的服务器是客户端),它有据我所知,对 IIS 没有影响??
-
很可能其中一台服务器没有安装 Excel 或至少没有安装 COM 组件。无论哪种方式,您都需要进行一些调试以找出未设置的对象。
-
@Lankymart 是正确的。服务器与此无关:脚本就像一个人在 Web 应用程序中执行某些操作。但是,取决于我访问网络应用程序的服务器,它是否可以正常工作。服务器不需要安装 Excel 或 COM 组件,因为如果我访问位于运行脚本的服务器中的 Web 会引发错误,那么 Web 应用程序完全可以通过人工交互来使用。
-
什么?!?抱歉,我在 处丢失了您“服务器不需要安装 Excel 或 COM 组件,因为如果我访问位于运行脚本的服务器中的 Web 会引发错误,那么 Web 应用程序对人类完全有用互动”...
-
在
iis-7与iis-7.5或IIS设置 中可能有所不同?对不起,我不太擅长IIS话题;你可以通过this question的链接向超级用户提问。
标签: vbscript iis-7 automation iis-7.5