当前位置: 首页 > 图文教程 > 网络编程 > Javascript > js玩一玩WSH吧

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 js玩一玩WSH吧


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 136 ::
收藏到网摘: n/a

Windows Script Host(Windows 脚本宿主)为 ActiveX 脚本引擎提供了一个不依赖于语言的脚本宿主。它允许通过 Windows 桌面或命令行来运行脚本。用来做一些需要批处理的事情是很方便的。
[玩一玩] 把下面代码保存为sendkeys.js,然后双击运行。
复制代码 代码如下:

var WshShell = new ActiveXObject("WScript.Shell");
WshShell.Run("Notepad");
WScript.Sleep(100);
WshShell.AppActivate("Notepad");
WScript.Sleep(100);
WshShell.SendKeys("Hello World!{ENTER}");
WScript.Sleep(500);
WshShell.SendKeys("^s");
WScript.Sleep(500);
WshShell.SendKeys("c:\\savedWorld.txt");
WScript.Sleep(500);
WshShell.SendKeys("%s");

WSH本身涉及的内容并不多,如果你基础好的话可以在40分钟以内基本掌握(也就是把教程浏览了一遍)。
这里有一个中文的教程,是 秋水 前辈留下的东西:http://www.blueidea.com/user/qswh/WSH.CHM
这个教程比较老了,新的资料可见于http://msdn.microsoft.com/library/en-us/script56/html/d78573b7-fc96-410b-8fd0-3e84bd7d470f.asp
剩下的就是调用你需要的 ActiveX 组件了,这也是Windows Scripting主要的乐趣所在。使 ActiveX 技术不过时的原因之一正是其在脚本中的应用。
除了直接的脚本应用之外,WSH还可以嵌入到其他程序中,Delphi和VB(6.0)程序通过这种办法来使用正则表达式。