三、WSH应用举例
WSH可以处理脚本程序,怎样阅读和编写WSH的脚本源文件呢?只要你有一点Basic(会VB的编程更好,呵呵)语言的基础,学会看懂WSH脚 本语言的程序并不是一件难事。去C:WINDOWSSAMPLESWSH目录以下将看看吧!里面提供了几类经典的脚本例子,而且分别提供了VBScript和 JavaScript两个版本,我们只要用记事本打开它们并仔细研究就不难学到一些基本的WSH应用。
你只需在记事本中依次输入以下每个实例中的代码,并保存为相应的“*.vbs”文件,双击这个文件,你就可以看到相应的效果了。
Q: How do I open script files? Trying the above solution makes Windows XP throw an error?
A: This is similar to the *.js association problem. Some machines seem to, for some reason, lose their *.vbs association. It's not that the files open with dreamweaver or whatever -- it's that the machine just doesn't know how to run them. If you have a scheduled task, "Could not run" will appear in the status column.
So, you're a smart person and read through the FAQ. You find the *.js extension problem, and you try that fix: you run it as "wscript c:pathtoscript.vbs". But that, in turn, produces a pop-up error, this time a "Windows Scripting Host" error: "There is no script engine for file extension '.vbs'." So, for some reason, wscript doesn't even know what to do with *.vbs files.
The solution to this problem is to run the script as:
wscript //e:vbscript c:pathtoscript.vbs
The "//e:vbscript" tells wscript to use the vbscript engine to parse the script. It will then run correctly.
A few alternative solutions, perhaps easier are:
Rename it .vbe (VBScript Encoded Script File). Not sure if this is a bad idea, but it seemed to work for some scripts.
Make a new association for VBS. Open up my computer, select Tools menu-> Folder Options, and go to the File Types tab. There probably isn't a VBS association listed if you have this problem. Select New, type in VBS, and hit Advanced>>. Then, from the pull-down menu, select "VBScript Script File". Making this selection automatically takes care of the association, along with the //e:vbscript problem. This is probably the "correct" solution...







