| Option | Description |
| I | The script executes interactively and terminates only at the end of its own code. This is the default setting. |
| B | The script suppresses all the message boxes and runs without requiring user intervention. |
| T:n | The script runs only for the specified n number of seconds. |
| nologo | No banner is displayed when the script executes. |
| logo | Displays a banner when the script starts. |
| S | The host saves the current command line for the current user. |
| H:host | Makes the specified host (cscript or wscript) the default scripting host for executing scripts. |
| ? | The scripting host command line is displayed. |
Figure 5 Windows Scripting Host Objects
| WScript Properties | Description |
| Application | Returns a pointer to the WScript IDispatch interface |
| Arguments | Returns a pointer to the WshArguments collection |
| FullName | Full path name to the scripting host |
| Interactive | The working mode of the scripting host (interactive or batch) |
| Name | Descriptive name of the scripting host |
| Path | Path name to the scripting host |
| ScriptFullName | Full path name of the script file that is currently running |
| ScriptName | File name of the script file that is currently running |
| Version | Version of the scripting host |
| WScript Methods | Description |
| CreateObject | Creates an instance of the specified object |
| GetObject | Returns a reference to the specified object |
| Echo | Displays its arguments to the default output device (window or console) |
| Quit | Terminates the execution of the script |
| WshShell Properties | Description |
| Environment | Returns a reference to a collection rendering the system environment |
| WshShell Methods | Description |
| CreateShortcut | Creates a shortcut to the specified path |
| ExpandEnvironmentStrings | Expands the specified environmental variable bracketed by % characters |
| Popup | Displays a message box |
| RegDelete | Deletes the specified registry key or value |
| RegRead | Returns the content of the specified registry key or value |
| RegWrite | Sets the specified registry key or value |
| Run | Starts the specified program |
| SpecialFolders | Returns the actual path for any special system folders |
| WshNetwork Properties | Description |
| ComputerName | Returns the name of the machine |
| UserDomain | Returns the user domain name |
| UserName | Returns the name of the current user |
| WshNetwork Methods | Description |
| AddPrinterConnection | Maps a remote printer |
| EnumNetworkDrives | Returns an object representing all the network drives |
| EnumPrinterConnections | Returns an object representing all the network printers |
| MapNetworkDrive | Maps a network drive |
| RemoveNetworkDrive | Disconnects a remote drive |
| RemovePrinterConnection | Disconnects a remote printer |
| SetDefaultPrinter | Sets the default printer |
Figure 6 Minor WSH Objects
| WshCollection Properties | Description |
| Item | Identifies the zero-based list of items |
| Count | Returns the number of items |
| Length | Same as Count |
| WshArguments Properties | Description |
| Item | Identifies the zero-based list of the arguments |
| Count | Returns the number of the arguments |
| Length | Same as Count |
| WshEnvironment Properties | Description |
| Item | Identifies the zero-based list of the environment variables |
| Count | Returns the length of the list |
| Length | Same as Count |
| WshEnvironment Methods | Description |
| Remove | Remove the specified variable |
| WshSpecialFolders Properties | Description |
| Item | Identifies the zero-based list of predefined system folders |
| Count | Returns the length of the list |
| Length | Same as Count |
| WshShortcut Properties | Description |
| Arguments | Identifies arguments for the shortcut |
| Description | Descriptive text for the shortcut |
| FullName | Full path name of .lnk file |
| Hotkey | A string like "Alt+Q" for the associated key combination |
| IconLocation | A string like "file, 1" to identify the icon to be displayed |
| TargetPath | The executable path associated with the shortcut |
| WindowStyle | A number denoting the required style for the window |
| WorkingDirectory | The working directory for the linked executable |
| WshShortcut Methods | Description |
| Save | Saves the .lnk file to disk |
| WshUrlShortcut Properties | Description |
| FullName | Full path name of .lnk file |
| TargetPath | The URL associated with the shortcut |
| WshUrlShortcut Methods | Description |
| Save | Saves the .lnk file to disk |
Figure 7 Creating a Shortcut
' Windows Script Host Sample Script
'
' This sample demonstrates how to use the WSHShell object to create a shortcut
' on the desktop.
L_Welcome_MsgBox_Message_Text = _
"This script will create a shortcut to Notepad on your desktop."
L_Welcome_MsgBox_Title_Text = "Windows Scripting Host Sample"
Call Welcome()
' ********************************************************************************
' *
' * Shortcut related methods.
' *
Dim WSHShell
Set WSHShell = WScript.CreateObject("WScript.Shell")
Dim MyShortcut, MyDesktop, DesktopPath
' Read desktop path using WshSpecialFolders object
DesktopPath = WSHShell.SpecialFolders("Desktop")
' Create a shortcut object on the desktop
Set MyShortcut = WSHShell.CreateShortcut(DesktopPath & _
"\Shortcut to notepad.lnk")
' Set shortcut object properties and save it
MyShortcut.TargetPath = WSHShell.ExpandEnvironmentStrings("%windir%\notepad.exe")
MyShortcut.WorkingDirectory = WSHShell.ExpandEnvironmentStrings("%windir%")
MyShortcut.WindowStyle = 4
MyShortcut.IconLocation = _
WSHShell.ExpandEnvironmentStrings("%windir%\notepad.exe, 0")
MyShortcut.Save
WScript.Echo "A shortcut to Notepad now exists on your Desktop."
' ********************************************************************************
' *
' * Welcome
' *
Sub Welcome()
Dim intDoIt
intDoIt = MsgBox(L_Welcome_MsgBox_Message_Text, _
vbOKCancel + vbInformation, _
L_Welcome_MsgBox_Title_Text )
If intDoIt = vbCancel Then
WScript.Quit
End If
End Sub
Figure 8 Disabling Registry Editor
' This code will disable the Registry Editor and
' show a popup message each time a user logon to
' the system.
Dim objShell
Set objShell = CreateObject( "WScript.Shell" )
s1 = "HKEY_USERS\.Default\Software\Microsoft\Windows\CurrentVersion\"
s2 = "Policies\System\DisableRegistryTools"
objShell.RegWrite s1+s2, 1, "REG_DWORD"
s1 = "HKLM\Software\Microsoft\Windows\CurrentVersion\WinLogon\"
s2 = "LegalNoticeCaption"
s3 = "LegalNoticeText"
objShell.RegWrite s1+s2, "Microsoft Interactive Developer"
objShell.RegWrite s1+s3, "Hi! Enjoy your MIND software!"
Figure 9 folder.vbs
s = InputBox( _
"Type the full path name of the new directory you want to create.", _
"New folder", "c:\" )
if s <> "" Then
set o = CreateObject( "Scripting.FileSystemObject" )
if Not o.FolderExists( s ) Then
o.CreateFolder s
end if
set o = Nothing
end if