Introduction to WSH (Windows Scripting Host)
WSH (Windows Script Host) will become an important player in every network administrator's team. The best way
to get started is by writing simple scripts. Feel free to amend my
examples to
suit your domain. In fact, discovering what happens when you change a name
here or command there, is the classic way to learn how WSH scripts work.
Topic - Simple WSH Script
The purpose of my
sample script is to check the version numbers of WSH, VBScript, WMI, and ADSI.
This is what the output of your script will look like. Note the subtle
differences in the names of the 4 executables: WSH, VBScript, WMI and ADSI. Check out the part of the
script where the major and minor version numbers are joined (concatenated) to
echo the final result.

Here is a sample script to check your version of WSH and WMI.
'Script to display WSH, VBScript, WMI, and ADSI
versions
'Script created by Guy Thomas
On Error Resume Next
WScript.Echo "WSH Version: " & WScript.Version
Wscript.Echo "VBScript Version: " & ScriptEngineMajorVersion _
& "." & ScriptEngineMinorVersion
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer _
& "\root\cimv2")
Set colWMISettings = objWMIService.ExecQuery _
("Select * from Win32_WMISetting")
For Each objWMISetting in colWMISettings
Wscript.Echo "WMI Version: " & objWMISetting.BuildVersion
Next
Set objShell = CreateObject("WScript.Shell")
strAdsiVersion = _
objShell.RegRead("HKLM\SOFTWARE\Microsoft\Active Setup\Installed
Components\{E92B03AB-B707-11d2-9CBD-0000F87A369E}\Version")
If strAdsiVersion = vbEmpty Then
strAdsiVersion = objShell.RegRead("HKLM\SOFTWARE\Microsoft\ADs\Providers\LDAP\")
If strAdsiVersion = vbEmpty Then
strAdsiVersion = "ADSI is not installed."
Else
strAdsiVersion = "2.0"
End If
End If
WScript.Echo "ADSI Version: " & strAdsiVersion
Copy the above script into Notepad Save with a .vbs extension,
e.g. guydemo.vbs. Double click to execute. Try another script?
Create Users The purpose of this script is to
add Organizational units and users. See Also
|