Echo 方法

将输出发送到对话框或控制台。

object.Echo [Arg1] [,Arg2] [,Arg3] ...

参数

object

WScript 对象。

Arg1, Arg2, Arg3 ...

所显示的项的列表。

说明

如果宿主为 WScript.exe,本方法将把输出显示在对话框中;如果宿主为 CScript.exe,结果将显示在控制台上。每一项将被一个空格隔开。 在 CScript.exe 下,输出的末尾被加上换行符。如果未提供任何项,显示的将是空行。

示例

下例演示了如何在两个使用不同脚本语言(VBScript and JScript)的任务中使用同一个 .wsf 文件。这两个任务的功能相同——显示当前机器的域名、计算机名、用户名及其驱动器和打印机的网络映射信息:

<package>

<job id="vbs">
<script language="VBScript">
   Set WshNetwork = WScript.CreateObject("WScript.Network")
   Set oDrives = WshNetwork.EnumNetworkDrives
   Set oPrinters = WshNetwork.EnumPrinterConnections
   WScript.Echo "Domain = " & WshNetwork.UserDomain
   WScript.Echo "Computer Name = " & WshNetwork.ComputerName
   WScript.Echo "User Name = " & WshNetwork.UserName
   WScript.Echo 
   WScript.Echo "Network drive mappings:"
   For i = 0 to oDrives.Count - 1 Step 2
      WScript.Echo "Drive " & oDrives.Item(i) & " = " & oDrives.Item(i+1)
   Next
   WScript.Echo 
   WScript.Echo "Network printer mappings:"
   For i = 0 to oPrinters.Count - 1 Step 2
      WScript.Echo "Port " & oPrinters.Item(i) & " = " & oPrinters.Item(i+1)
   Next
</script>
</job>

<job id="js">
<script language="Javascript">
   var WshNetwork = new ActiveXObject("WScript.Network");
   var oDrives = WshNetwork.EnumNetworkDrives();
   var oPrinters = WshNetwork.EnumPrinterConnections();
   WScript.Echo("Domain = " + WshNetwork.UserDomain);
   WScript.Echo("Computer Name = " + WshNetwork.ComputerName);
   WScript.Echo("User Name = " + WshNetwork.UserName);
   WScript.Echo();
   WScript.Echo("Network drive mappings:");
   for(i=0; i<oDrives.Count(); i+=2){
      WScript.Echo("Drive " + oDrives.Item(i) + " = " + oDrives.Item(i+1));
   }
   WScript.Echo();
   WScript.Echo("Network printer mappings:");
   for(i=0; i<oPrinters.Count(); i+=2){
      WScript.Echo("Port " + oPrinters.Item(i) + " = " + oPrinters.Item(i+1));
   }
</script>
</job>

</package>

详细信息请参阅:运行脚本

请参阅

应用于: WScript 对象