共用方式為


使用 VBScript

[從 Windows 7 開始,Microsoft Agent 已被取代,而且在後續版本的 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... 來指定事件處理常式 事件 語法:

<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>