WSH 5.6 可以运行驻留在远程系统上的脚本。下面的脚本将演示该功能。这些脚本假定文件位于一个叫做 "c:\wsh5.6" 的本地计算机目录上;必要时更改本地路径和远程计算机名称。
在本地计算机上最初运行 RemoteTest.WSF 之后,DCOM 验证您的身份时可能会有一个短暂的中断。在看到 "Done" 消息后,远程计算机上名为 "c:\beenhere.txt" 的文件会指明您执行命令的时间(以远程计算机的时钟为准)。
// JScript。 RemoteTest.WSF ------------------------------- <package> <job> <script language="JScript"> var oController = new ActiveXObject("WSHController"); var oProcess = oController.CreateScript("c:\\wsh5.6\\beenhere.wsf","remmachine"); oProcess.Execute(); while (oProcess.Status != 2) WScript.Sleep(100); WScript.Echo("Done"); </script> </job> </package> -------------------------------
BeenHere.WSF ------------------------------- <package> <job> <script language="JScript"> var fso = new ActiveXObject("Scripting.FileSystemObject"); var fout = fso.CreateTextFile("c:\\beenhere.txt",true); fout.WriteLine(new Date); fout.Close(); </script> </job> </package> ------------------------------- ' VBScript。 RemoteTest.WSF ------------------------------- <package> <job> <script language="VBScript"> set oController = CreateObject("WSHController") set oProcess = oController.CreateScript("c:\wsh5.6\beenhere.wsf","remmachine") oProcess.Execute While oProcess.Status <> 2 WScript.Sleep 100 WEnd WScript.Echo "Done" </script> </job> </package> ------------------------------- BeenHere.WSF ------------------------------- <package> <job> <script language="VBScript"> set fso = CreateObject("Scripting.FileSystemObject") set fout = fso.CreateTextFile("c:\beenhere.txt",true) fout.WriteLine Now fout.Close </script> </job> </package>