将文本输出到消息框中或命令控制台窗口。
object.Echo [Arg1] [,Arg2] [,Arg3] ...
Echo 方法的运行方式取决于使用的 WSH 引擎。
WSH 引擎 | 文本输出 |
---|---|
Wscript.exe | 图形消息框 |
Cscript.exe | 命令控制台窗口 |
显示的各项之间用空白字符隔开。如果使用 CScript.exe,则各项之间用换行符隔开。如果未向 Echo 方法提供任何作为参数的项,则输出一个空行。
下面的示例使用 Echo 方法显示当前的域名、计算机名和用户名,并显示驱动器和打印机的网络映射信息。
<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="JScript"> var WshNetwork = WScript.CreateObject("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>