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

Javascript
Add a Table to a Word Document
Add Formatted Text to a Word Document
用jscript实现新建word文档
用jscript实现新建和保存一个word文档
Open and Print a Word Document
Use Word to Search for Files
Convert Seconds To Hours
Sample script that deletes a SQL Server database
Sample script that displays all of the users in a given SQL Server DB
firefox中用javascript实现鼠标位置的定位
div+css实现鼠标放上去,背景跟图片都会变化。
Locate a File Using a File Open Dialog Box
Save a File Using a File Save Dialog Box
用jscript实现列出安装的软件列表
List the Stored Procedures in a SQL Server database
Display SQL Server Login Mode
Display SQL Server Version Information
List all the Databases on a SQL Server
用jscript启动sqlserver
Stop SQL Server

Javascript 中的 js玩一玩WSH吧


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 141 ::
收藏到网摘: 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)程序通过这种办法来使用正则表达式。