共用方式為


使用 VBScript

[Microsoft代理程式從 Windows 7 開始已被取代,而且可能無法在後續版本的 Windows 中使用。]

VBScript 是隨附於 Microsoft Internet Explorer 的程式設計語言。 如需其他瀏覽器,請連絡您的廠商以取得支援。 建議搭配 Agent 使用 VBScript 2.0 (或更新版本)。 雖然舊版的 VBScript 可能會與 Agent 搭配運作,但它們缺少您可能想要使用的特定函式。 您可以下載 VBScript 2.0,並在 Microsoft 下載網站和 Microsoft VBScript 網站取得 VBScript 的進一步資訊。

若要從 VBScript Microsoft Agent 進行程序設計,請使用 HTML <SCRIPT> 標記。 若要存取程式設計介面,請使用您在 <OBJECT> 標記中指派的控件名稱,後面接著子物件(如果有的話)、方法或屬性的名稱,以及方法或屬性所支援的任何參數或值:

agent[.object].Method parameter, [parameter]
agent[.object].Property = value

針對事件,請包含控制項的名稱,後面接著事件的名稱和任何參數:

Sub agent_event (ByVal parameter[,ByVal parameter])
statements
End Sub

您也可以使用 <SCRIPT> 標記的 For...Event 語法指定事件處理程式:

<SCRIPT LANGUAGE=VBScript For=agent Event=event[(parameter[,parameter])]>
statements
</SCRIPT>

雖然Microsoft Internet Explorer 支援後者的語法,但並非所有瀏覽器都支援。 為了相容,請只針對事件使用先前的語法。

使用 VBScript (2.0 或更新版本),您可以嘗試建立物件並檢查是否存在,以確認是否已安裝 Microsoft Agent。 下列範例示範如何檢查 Agent 控件,而不觸發控件的自動下載(如果您已在頁面上包含控件的 <OBJECT> 標籤,就可能發生):

<!-- WARNING - This code requires VBScript 2.0.
It will always fail to detect the Agent control
in VbScript 1.x, because CreateObject doesn't work.
-->

<SCRIPT LANGUAGE=VBSCRIPT>
If HaveAgent() Then
      'Microsoft Agent control was found.
document.write "<H2 align=center>Found</H2>"
Else
      'Microsoft Agent control was not found.
document.write "<H2 align=center>Not Found</H2>"
End If

Function HaveAgent()
' This procedure attempts to create an Agent Control object.
' If it succeeds, it returns True.
'    This means the control is available on the client.
' If it fails, it returns False.
'    This means the control hasn't been installed on the client.

   Dim agent
   HaveAgent = False
   On Error Resume Next
   Set agent = CreateObject("Agent.Control.1")
   HaveAgent = IsObject(agent)

End Function

</SCRIPT>