通過顯示腳本的使用方法使腳本具有自我說明性。
object.ShowUsage
運行 ShowUsage 方法時,將出現(xiàn)幫助屏幕(稱為用法),并顯示有關(guān)腳本命令行選項的詳細信息。該信息來自 *.WSF 文件的運行時部分。在 <runtime> 和 </runtime> 標(biāo)記之間編寫的任何語句都將組合起來,以便生成所謂的“用法語句”。用法語句告訴用戶如何使用腳本。
注意 還可使用 /? 開關(guān)顯示用法。
下面的示例演示如何在 *.WSF 腳本文件中設(shè)置用法信息。
<job>
<runtime>
<description>This script reboots a server</description>
<named
name = "Server"
helpstring = "Server to run the script on"
type = "string"
required = "true"
/>
<example>Example: reboot.wsf /server:scripting</example>
</runtime>
<script language="VBScript">
If WScript.Arguments.Count <> 1 Then
WScript.Arguments.ShowUsage
WScript.Quit
End If
</script>
</job>
相應(yīng)的 Jscript 腳本代碼塊為:
if (WScript.Arguments.length != 1)
{
WScript.Arguments.ShowUsage
();
WScript.Quit();
}
從該腳本中調(diào)用 ShowUsage 方法將生成下列輸出:
This script reboots a server Usage: reboot.wsf /server:value Options: server : Server to run the script on Example: reboot.wsf /server:scripting