Introduction to WSH
Author:Eve Cole
Update Time:2009-05-30 19:53:53
1. Overview Although not only NT5 has WSH, NT5 (WINDOWS2000) must have WSH. In fact, if you are in WIN98+PWS or NT4+IIS4, you can find
WSH.
WSH is a type of Microsoft scripting technology series. Simply put, it provides a scripting environment in which some objects are predefined and can also be used.
Other objects in COM. He uses a script engine to interpret and execute scripts. Microsoft itself supports VBSCRIPT and JSCRIPT, and third parties can also develop their own script engines.
To be specific, you first compile some script files (Microsoft comes with several examples, suffixed with .vbs or .js), and then use a program to interpret and execute them. This program is called
Windows Scripting Host, the name of the program is Wscript.exe (or Cscript.exe in the command line). You can check whether there are these two files in your machine to know whether there is WSH. This is very much like a batch file, except that instead of a command line, the file contains a script written in a scripting language. At the same time, the functions he completes are very similar to batch files, but with more control.
I mainly use WSH to complete some tedious tasks that usually require me to perform repeated operations, such as setting ACLs for a large number of directories, or creating a large number of directories, etc.
Although this can also be achieved by writing VB or VC programs, it is more troublesome than scripting. It requires at least such a large environment, while scripting only requires a writing pad. Use WSH
Technology to configure the server, including creating users, creating mailboxes, creating directories, creating sites, setting ACL, and setting FrontPage ServerExtention. I will introduce it in detail in several lectures in the WSH practical lecture.
2.Composition
Several built-in objects that come with WSH include:
1. Object provided by Wscript.exe
Wscript is exposed to scripting engines as Wscript.
WshArguments Undocumented; accessed through the Wscript.Arguments property.
2. Object provided by WSHom.Ocx.
WshShell automatic object.
ProgID is Wscript.WshShell.
WshNetwork automatic object. ProgID is Wscript.WshNetwork.
WshShortcut Undocumented; accessed through the WshShell.CreateShortcut method.
WshUrlShortcut Undocumented; accessed through the WshShell.CreateShortcut method.
WshCollection Not public; accessed through the WshNetwork.EnumNetworkDrives or WshNetwork.EnumPrinterConnection methods.
WshEnvironment Undocumented; accessed through the WshShell.Environment property.
WshSpecialFolders Undocumented; accessed through the WshShell.Folder property.
They can mainly complete functions such as obtaining environment variables, network login, drive mapping, creating quick screenshots, loading programs, and obtaining information on special folders (such as system folders).
If your system supports COM components such as ADO, you can also use it.
3.Example
The following example demonstrates opening WordPad to view a text file, and at the same time creating a text file and writing a paragraph. You can copy it to WordPad and then use it as .vbs
Save the suffix and then double-click it.
'test.vbs
Set WshShell = Wscript.CreateObject("Wscript.Shell")
WshShell.Run ("notepad " & Wscript.ScriptFullName)
'Use SHELL object to start the program above
Set fs = Wscript.CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile("c:testfile.txt", True)
a.WriteLine("This is a test.")
a.Close
'Use COM object Scripting.FileSystemObject to operate text files
4. Where to find study materials
There are very complete WSH documents in the product documentation of PWS and IIS4. It is recommended that you study first to understand the basic knowledge of WSH.