Windows Script Host Version 2.0 Tutorial

Microsoft® Windows® Script Host
Windows Script Host Version 2.0 Tutorial 		WSH Reference
Next

To | See
See a list of conventions used throughout this tutorial | Document Conventions
Get an overview of Windows Script Host | About Windows Script Host
Learn about Windows Script (.wsf) files | Using Windows Script Files
Customize the way your scripts run | Customizing Script Settings
Create files for setting properties in your scripts | Setting Script Properties
Get an overview of running scripts | Running Your Scripts
Run scripts from the Windows environment | Running Scripts with WScript.exe
Run scripts from the command prompt | Running Scripts with CScript.exe
Run scripts with drag and drop functionality | Drag and Drop Support
View the Windows Script Host Reference | Windows Script Host Reference
View a list of Windows Script Host error messages | Windows Script Host Error Messages
View a list of features by version | Version Information


Document Conventions

Document Conventions 		WSH Tutorial
Next

The following conventions are used throughout this tutorial:

  • Scripting examples are written in the Microsoft Visual Basic® Scripting Edition (VBScript) language.
  • Methods written in Microsoft JScript® are case-sensitive. In general, you should use the same case as the syntax examples in this document.
  • Parameters in brackets (for example, [anyValue]) are optional.

The following table lists variable prefixes in parameter listings and code examples, and their corresponding descriptions.

Prefix | Description
any | Any type
b | Boolean
int | Integer
nat | Natural number or nonnegative integer
obj | Object (IDispatch interface)
str | String


About Windows Script Host

About Windows Script Host 		WSH Tutorial
Previous
Next

Microsoft® Windows® Script Host is a language-independent scripting host for ActiveX® scripting engines. It brings simple, powerful, and flexible scripting to the Windows 32-bit platform, allowing you to run scripts from both the Windows desktop and the command prompt.

Windows Script Host is ideal for non-interactive scripting needs such as logon scripting, administrative scripting, and machine automation.

The Benefits of Windows Script Host

Windows Script Host offers the following benefits:

  • Two separate executable files, WScript.exe and CScript.exe, for running scripts either from Windows or from the command prompt. WScript.exe provides a Windows-based properties page for setting script properties, while CScript.exe provides command-line switches for setting script properties.
  • Support for multiple files. You can call multiple scripting engines and perform multiple jobs from a single Windows Script (.wsf) file.
  • Very low memory requirements.
  • Mapping of script extensions to programmatic identifiers (ProgIDs). When you start a script from the Windows desktop or the command prompt, the script host reads and passes the specified script file contents to the registered script engine. Instead of using the HTML SCRIPT tag to identify the script, the host uses file extensions; for example, .vbs for Microsoft Visual Basic® Scripting Edition (VBScript) files, and .js for Microsoft JScript® files. The use of extensions means you no longer need to be familiar with the ProgID for a given script engine. Windows Script Host handles this for you by maintaining a mapping of script extensions to ProgIDs, launching the appropriate engine for a given script.
Windows Script Host Object Model
Windows Script Host provides ActiveX interfaces for direct manipulation of script execution, as well as helper functions for other actions. The Windows Script Host Reference documents elements, methods, objects, and properties with which you can accomplish tasks such as the following:
  • Print messages to the screen
  • Run basic functions such as CreateObject and GetObject
  • Map network drives
  • Connect to printers
  • Retrieve and modify environment variables
  • Modify registry keys
Windows Script Host Integration
Windows Script Host is integrated into Windows 98, Windows 2000 Professional, and Windows 2000 Server. Version 2.0 includes the VBScript and JScript scripting engines. In the future, other software companies may provide ActiveX scripting engines for languages such as PerlScript, TCL, REXX, and Python.


Using Windows Script Files

Using Windows Script Files 		WSH Tutorial
Previous
Next

The Windows script (.wsf) file, a text document containing Extensible Markup Language (XML) code, incorporates several features that offer you increased scripting flexibility. Because Windows script files are not engine-specific, they can contain script from any ActiveX®-compliant scripting engine.

With .wsf files, you can take advantage of the following benefits as you create your scripts:

  • Support for Include statements - allows you to incorporate previously-written functions from VBScript or JScript files into your Windows Script Host project.
  • Support for multiple engines - allows you to use more than one scripting language per file.
  • Support for Type libraries - allows you to add constants to your code.
  • Support for tools - allows you to edit files with any XML editor.
  • Support for multiple jobs in one file - allows you to store all of your code in a single location.
Include Statements
If you have .js and .vbs files from previous Windows Script Host projects, a .wsf file enables you to use them with Windows Script Host. A .wsf file encapsulates a library of functions that can in turn be used by multiple .wsf files.

The following example shows the contents of a .wsf file that includes a JScript file (fso.js), plus a VBScript function that calls a function (GetFreeSpace) in the included file. The contents of fso.js are provided also.

<Job id="IncludeExample">
<script language="JScript" src="FSO.JS"/>
<script language="VBScript">
    ' Get the free space for drive C.
    s = GetFreeSpace("c:")
    WScript.Echo s
</Script>
</Job>
Contents of fso.js:
function GetFreeSpace(drvPath) {
    var fs, d, s;
    fs = new ActiveXObject("Scripting.FileSystemObject");
    d = fs.GetDrive(fs.GetDriveName(drvPath));
    s = "Drive " + drvPath + " - " ;
    s += d.VolumeName;
    s += " Free Space: " + d.FreeSpace/1024 + " Kbytes";
    return s;
}
Multiple-Engine Support
Since one scripting language may not have all the functionality you need, Windows Script Host allows you to combine multiple languages in a single .wsf file. The following example shows the contents of a .wsf file that includes both VBScript® and PerlScript code:
<job id="PERLandVBS">
<script language=PerlScript RUNAT=Server>
    sub PerlHello
    {
        my $str = @_[0];
        $WScript->Echo($str);
    }
</script>

<script language="VBScript">
    WScript.Echo "Hello from VBScript"
    PerlHello "Hello from PERLScript"
</Script>
</Job>
Type Library Support
In the following example, MyComponent was developed with Microsoft® Visual Basic® 5.0. MyComponent defines the constant MyError with the following statement.
Public Const MyError = "You are not using MyComponent correctly."
The type library is contained in mycomponent.lib, which you have installed in C:\MyComponent.
<Job id="IncludeExample">
<Reference progid="MyComponent.MyClass">
<Script language="VBScript">
    Dim MyVar
    Set MyVar = CreateObject("MyComponent.MyClass")
    Currentreturn = MyVar.MyMethod
    If Currentreturn = False then
        WScript.Echo MyError
    End If
</Script>
</Job>
Tools Support
Since the .wsf file is in XML format, you can use any editor that supports XML to edit .wsf files. You can also use any text editor, such as Notepad.
Multiple Jobs in One File
Instead of keeping all your scripts in separate files, you can incorporate them all into one .wsf file and break them into several different jobs. You can then run each job separately using syntax similar to the following example, where MyFirstJob is the name of the job contained in the MyScripts.wsf file:
CScript //Job:MyFirstJob MyScripts.wsf


Customizing Script Settings

Customizing Script Settings 		WSH Tutorial
Previous
Next

You can record specific settings for each of your individual scripts by means of a Windows Script Host control (.wsh) file. The .wsh file is a text document in which you can customize execution of one or more of your scripts.

You can create multiple .wsh files for a single script, which enables you to tailor the way the script runs to the needs of specific groups or even individuals within an organization. Thus a single logon script, invoked by two different .wsh files containing different settings and parameters, can be made to serve two very different groups.

The .wsh file is analogous to the PIF file used to run older 16-bit applications. It is created automatically when you set the properties for a supported script file. You can treat it as if it were an executable file or batch file.

For example, suppose you have a script named Myscript.vbs for which you have created a .wsh file named Myscript.wsh. To run Myscript.vbs with the options recorded in Myscript.wsh, you can either double-click Myscript.wsh in Windows Explorer, or pass Myscript.wsh as a script argument to CScript.exe or WScript.exe. You could do the latter by entering the following command at the command prompt:

c:\>cscript Myscript.wsh
For details, see Setting Script Properties.


Setting Script Properties

Setting Script Properties 		WSH Tutorial
Previous
Next

For each individual script you run, you can record specific settings by means of a control (.wsh) file. A .wsh file is a text file that uses a format similar to that of .ini files. It is created automatically when you set the properties for a supported script file.

To create a .wsh file for a given script
  1. Right-click the script file in Windows Explorer.
  2. Choose Properties on the context menu.
  3. Choose the settings you want for the script on the property page.
  4. Click OK or Apply.
A .wsh file is created with the same name as the script file you right-clicked. A sample .wsh file might contain the following text:
[ScriptFile]
Path=C:\WINNT\Samples\WSH\showprop.vbs
[Options]
Timeout=0
DisplayLogo=1
BatchMode=0
The Path setting in the [ScriptFile] section identifies the script file that this .wsh file is associated with. The keys in the [Options] section correspond to settings in the Script tab within the Properties dialog box.
How the .wsh file works

When you double-click the .wsh file or execute it from the command line, CScript.exe or WScript.exe reads the .wsh file to determine the specific settings that should be used to execute the script. CScript/WScript executes the original script, passing in the properties that are defined within the .wsh file.

It is important to note that you must have the original script file present when executing the .wsh file. If the .wsh file fails to execute the script, check the Path= entry in the .wsh file to ensure that it is pointing to the script you are attempting to run.


Running Your Scripts

Running Your Scripts 		WSH Tutorial
Previous
Next

To | See
Run a script from the Windows environment | Running Scripts with WScript.exe
Run a script from the command prompt | Running Scripts with CScript.exe
Use drag and drop functionality | Drag and Drop Support


Running Scripts with WScript.exe

Running Scripts with WScript.exe 		WSH Tutorial
Previous
Next

WScript.exe is the version of Windows Script Host that enables you to run scripts from Windows. WScript.exe provides a Windows-based dialog box for setting script properties. Using WScript.exe, you can run scripts under Windows in the following ways:
  • Double-click files or icons. These can be files or icons listed in My Computer, Windows Explorer, the Find window, the Start menu, or on the Desktop.
  • Enter a script name at the Run command on the Start menu. Press the Start button, choose Run, and then enter the full name of the script you want to run, including its file extension and any necessary path information.
  • Enter WScript.exe, followed by a script name, at the Run command. Press the Start button, select Run, and enter WScript, followed by the full name and path of the script you want to run.
If you double-click a script file whose extension has not yet been associated with WScript.exe, an Open With dialog box appears, asking which program to use to open the file. Choose WScript and check Always use this program to open this file check box to register WScript as the default application for all files having the same extension as the one you double-clicked. For example, if you check this check box when you run Chart.vbs, WScript.exe becomes the default application for all files having the .vbs extension.

The WScript.exe properties dialog box provides the following options:

Property | Description | CSCRIPT equivalent
Stop script after specified number of seconds. | Specifies the maximum number of seconds that a script can run. The default is no limit. | //T:nn
Display logo when script is executed in command console. Displays a banner before running the script. This is the default. The opposite is //nologo. //logo or
//nologo

Using the WScript.exe Properties dialog box, you can set global scripting options for all scripts that WScript runs on the local machine. You can also set options for individual scripts, using a .wsh file. For details, see Setting Script Properties.

When Windows Script Host ships with Windows NT® 2000, you will no longer need to provide the script file's extension. Instead, you can type the script name alone, or double-click the script in Windows Explorer.


Running Scripts with CScript.exe

Running Scripts with CScript.exe 		WSH Tutorial
Previous
Next

CScript.exe is the version of Windows Script Host that enables you to run scripts from the command prompt. CScript.exe provides command-line switches for setting script properties. To use CScript.exe, type a command line at the command prompt using the following syntax:
cscript [host options...] [script name] [script options and parameters]
where the terms are defined as follows:
  • Host options enable or disable various Windows Script Host features. Host options are preceded by two slashes (//).
  • Script name is the name of the script file, complete with extension and any necessary path information, such as: d:\admin\vbscripts\chart.vbs.
  • Script options and parameters are passed to the script. Script parameters are preceded by a single slash (/).
Each parameter is optional; however, you cannot specify script options without specifying a script name. If you do not specify parameters, CScript displays the CScript syntax and the valid host parameters. CScript.exe supports the host options shown in the following table.

Parameter | Description
//I | Interactive mode: allows display of user prompts and script errors (this is the default, and the opposite of //B).
//B | Batch mode: suppresses command-line display of user prompts and script errors.
//T:nn | Enables time-out: the maximum number of seconds the script can run. The default is no limit. (See the text following this table for more information on this parameter.)
//logo | Default. Displays a banner (opposite of //nologo).
//nologo | Prevents display of an execution banner at run time.
//H:CScript or
//H:WScript 		Registers CScript.exe or WScript.exe as the default application for running scripts. If neither is specified, WScript.exe is assumed as the default.
//S | Saves the current command-line options for this user.
//? Shows command usage (same as with parameters).
//E:engine | Executes the script with the specified scripting engine.
//D | Turns on the debugger.
//X | Launches the program in the debugger.
//Job:<JobID> | Runs the specified JobID from the .wsf file.

The //T parameter prevents excessive execution of scripts by setting a timer. When execution time exceeds the specified value, CScript interrupts the scripting engine using the IActiveScript::InterruptThread method and terminates the process.

A CScript Example
Several sample scripts are installed when you install the final release of the Windows Script Host. These are also available for download at: http://msdn.microsoft.com/scripting

Suppose, for the purposes of this example, that you have copied the Chart.vbs sample script to the following folder on your computer:

c:\sample scripts\chart.vbs

You can run the script with and without a logo, as follows:

  1. Choose the MS-DOS® operating system command prompt from Programs on the Start menu.
  2. Enter the following commands at the command prompt (modify accordingly if your sample scripts are located in a different folder):
cscript //logo c:\"sample scripts"\chart.vbs
cscript //nologo c:\"sample scripts"\chart.vbs


Drag and Drop Support

Drag and Drop Support 		WSH Tutorial
Previous
Next

The Windows operating system currently supports drag and drop with batch files. This functionality, which enables you to drag one or more files onto a batch file and then run it with the files as arguments, is now supported in Windows Script Host version 2.0 as well.

When you drag files onto a WSH script, the file names are translated into arguments on the command line. These file names can be displayed in a list, which you can use to manipulate files with any scripting object.

To display a script's argument list

  1. Create a file and give it a name with a .vbs extension (for example, DragDrop.vbs).

  2. Add the following code to the .vbs file:

    3. Set objArgs = WScript.Arguments
For I = 0 to objArgs.Count - 1
  WScript.Echo objArgs(I)
Next
  3. Save the file to your hard drive.

  4. Drag and drop any file or files onto your .vbs file. The file names are echoed back to the screen.

Remarks
The number of files you can drag onto a script is limited by the maximum command-line length your system allows. If the total number of characters in all file names being dragged exceeds this limit, the dragging and dropping operation will fail.


Microsoft Windows Script Host Reference

Windows Script Host Reference 		WSH Tutorial
Version Information

Alphabetic Keyword List

Elements

Errors

Methods

Objects

Properties

Welcome to the Windows Script Host Reference

These handy blocks of information will help you explore the many different parts of the Windows Script Host.

You'll find all the parts of WSH listed alphabetically under the Alphabetic Keyword List. But if you want to examine just one category, say, objects, each language category has its own, more compact section.

How does it work? Click on one of the headings to the left to display a list of items contained in that category. From this list, select the topic that you want to view. Once you've opened that topic, you can easily link to other related sections.

So, go ahead and take a look! Study some elements, mull over the methods, or figure out a few properties. You'll see just how versatile WSH can be!

Language Element | Description
<?job ?> Element | XML processing instruction that specifies attributes for error handling.
<?XML ?> Element | Indicates that the file should be parsed as XML.
AddPrinterConnection Method | Maps the remote printer specified by strRemoteName to the local resource name strLocalName.
AddWindowsPrinterConnection Method | Adds a printer connection to Windows.
AppActivate Method | Activates an application window.
Application Property | Provides the IDispatch interface on the WScript object.
Arguments Property | Returns a pointer to the WshArguments collection or identifies arguments for the shortcut.
AtEndOfLine Property | Returns True if the stream pointer immediately precedes the end-of-line marker in an input stream; False if it is not.
AtEndOfStream Property | Returns True if the stream pointer is at the end of an input stream; False if it is not.
Close Method | Closes an open stream.
Column Property | Returns the column number of the current character position in an input stream.
ComputerName Property | Provides a string representation of the computer name.
ConnectObject Method | Connects an objects event sources to functions with a given prefix.
Count Property | Returns the number of enumerated items.
CreateObject Method | Creates an object specified by the strProgID parameter.
CreateShortcut Method | Creates an object reference to a shortcut or URLshortcut.
Description Property | Provides a description of a shortcut object.
DisconnectObject Method | Disconnects a previously connected object from Windows Script Host.
Echo Method | Displays parameters in a window.
EnumNetworkDrives Method | Returns the current network drive mappings.
EnumPrinterConnections Method | Returns the current network printer mappings.
Environment Property | Returns the WshEnvironment object.
Errors | Lists Windows Script Host error messages.
ExpandEnvironmentStrings Method | Expands the PROCESS environment variable and returns the result string.
FullName Property | Returns a string containing the full path to the host executable or shortcut object.
GetObject Method | Retrieves an Automation object from a file, or an object specified by the strProgID parameter.
getResource Method | Gets the value of a resource defined with the <resource> element.
HotKey Property | Provides the hotkey of a shortcut object.
IconLocation Property | Provides the icon location of a shortcut object.
Item Property | Returns a specified item from a collection.
<job> Element | Allows for multiple jobs to be defined in a single file. Since this is an enclosing tag, every tag within the Job tag will apply to that job.
Length Property | Returns the number of enumerated items.
Line Property | Returns the current line number in an input stream.
LogEvent Method | Logs an event in the Windows NT event log or WSH.log file.
MapNetworkDrive Method | Maps the share point specified by strRemoteName to the local resource name strLocalName.
Name Property | Provides a string containing the friendly name of the WScript object.
<object> Element | XML element used in scriptlet files that defines objects that can be referenced by script.
<package> Element | Encloses multiple job definitions.
Path Property | Provides a string containing the name of the directory where WScript.Exe or Cscript.Exe resides.
Popup Method | Displays a popup message box window that contains the message contained in strText.
Quit Method | Quits execution with a specified error code.
Read Method | Reads a specified number of characters from an input stream and returns the resulting string.
ReadAll Method | Reads an entire input stream and returns the resulting string.
ReadLine Method | Reads an entire line (up to, but not including, the newline character) from an input stream and returns the resulting string.
<reference> Element | XML element used in Windows Script Component files that includes a reference to an external type library.
RegDelete Method | Deletes from the registry the key or value named strName.
RegRead Method | Returns the registry key or value named by strName.
RegWrite Method | Sets the registry key or value named by strName.
Remove Method | Deletes the environment variable specified by strName.
RemoveNetworkDrive Method | Removes the current resource connection denoted by strName.
RemovePrinterConnection Method | Removes the current resource connection denoted by strName.
<resource> Element | XML element isolates textual or numeric data that should not be hard-coded into the scripts.
Run Method | Creates a new process that executes strCommand.
Save Method | Saves a shortcut to the specified location.
<script> Element | XML element that contains script to define the Windows Script Component's behavior.
ScriptFullName Property | Provides the full path to the script being run.
ScriptName Property | Provides the file name of the script being run.
SendKeys Method | Sends one or more keystrokes to the active window as if typed at the keyboard.
SetDefaultPrinter Method | Sets the default printer to the remote printer specified.
Skip Method | Skips a specified number of characters when reading an input stream.
SkipLineMethod | Skips the next line when reading an input stream.
Sleep Method | Places the script process into an inactive state for the number of milliseconds specified and then continues execution.
SpecialFolders Property | Provides the WshSpecialFolders object for accessing Windows shell folders such as the desktop folder, the Start menu folder, and the personal document folder.
StdErr Property | Exposes the write-only error output stream for the current script.
StdIn Property | Exposes the read-only input stream for the current script.
StdOut Property | Exposes the write-only output stream for the current script.
TargetPath Property | Sets the path of the file to execute of a shortcut object.
UserDomain Property | Provides a string representation of the user domain name.
UserName Property | Provides a string representation of the user name.
Version Property | Returns the version of the Windows Script Host.
WindowStyle Property | Provides the window style of a shortcut object.
WorkingDirectory Property | Provides the working directory of a shortcut object.
Write Method | Writes a specified string to an output stream.
WriteBlankLines Method | Writes a specified number of newline characters to an output stream.
WriteLine Method | Writes a specified string and newline character to an output stream.
WScript Object | Exposes properties that tell the path of the running scripting host (wscript.exe or cscript.exe), its arguments, and the working mode (interactive or batch). The WScript object also provides methods to create and read objects.
WshArguments Object | Returns a pointer to the collection of command-line parameters.
WshEnvironment Object | Retrieves the system environment variables.
WshNetwork Object | Maps the network, making it easy to connect and disconnect remote drives and printers.
WshShell Object | Starts a new process and creates shortcuts, and provides the Environment collection to handle environmental variables such as WINDIR, PATH, or PROMPT.
WshShortcut Object | Creates an object reference to a shortcut.
WshSpecialFolders Object | Accesses the Windows shell folders such as the desktop folder, the Start menu folder, and the personal document folder.
WshUrlShortcut Object | Creates an object reference to URLshortcut.
Language Element | Description
<?job ?> Element | XML processing instruction that specifies attributes for error handling.
<?XML ?> Element | Indicates that the file should be parsed as XML.
<job> Element | Allows for multiple jobs to be defined in a single file. Since this is an enclosing tag, every tag within the Job tag will apply to that job.
<object> Element | XML element used in Windows Script Component files that defines objects that can be referenced by script.
<package> Element | Encloses multiple job definitions.
<reference> Element | XML element used in Windows Script Component files that includes a reference to an external type library.
<resource> Element | XML element isolates textual or numeric data that should not be hard-coded into the scripts.
<script> Element | XML element that contains script to define the Windows Script Component's behavior.
Language Element | Description
Error List | List of Windows Script Host Error messages.
Language Element | Description
AddPrinterConnection Method | Maps the remote printer specified by strRemoteName to the local resource name strLocalName.
AddWindowsPrinterConnection Method | Adds a printer connection to Windows.
AppActivate Method | Activates an application window.
Close Method | Closes an open stream.
ConnectObject Method | Connects an objects event sources to functions with a given prefix.
CreateObject Method | Creates an object specified by the strProgID parameter.
CreateShortcut Method | Creates an object reference to a shortcut or URLshortcut.
DisconnectObject Method | Disconnects a previously connected object from Windows Script Host.
Echo Method | Displays parameters in a window.
EnumNetworkDrives Method | Returns the current network drive mappings.
EnumPrinterConnections Method | Returns the current network printer mappings.
ExpandEnvironmentStrings Method | Expands the PROCESS environment variable and returns the result string.
GetObject Method | Retrieves an Automation object from a file, or an object specified by the strProgID parameter.
getResource Method | Gets the value of a resource defined with the <resource> element.
LogEvent Method | Logs an event in the Windows NT event log or WSH.log file.
MapNetworkDrive Method | Maps the share point specified by strRemoteName to the local resource name strLocalName.
Popup Method | Displays a popup message box window that contains the message contained in strText.
Quit Method | Quits execution with a specified error code.
Read Method | Reads a specified number of characters from an input stream and returns the resulting string.
ReadAll Method | Reads an entire input stream and returns the resulting string.
ReadLine Method | Reads an entire line (up to, but not including, the newline character) from an input stream and returns the resulting string.
RegDelete Method | Deletes from the registry the key or value named strName.
RegRead Method | Returns the registry key or value named by strName.
RegWrite Method | Sets the registry key or value named by strName.
Remove Method | Deletes the environment variable specified by strName.
RemoveNetworkDrive Method | Removes the current resource connection denoted by strName.
RemovePrinterConnection Method | Removes the current resource connection denoted by strName.
Run Method | Creates a new process that executes strCommand.
Save Method | Saves a shortcut to the specified location.
SendKeys Method | Sends one or more keystrokes to the active window as if typed at the keyboard.
SetDefaultPrinter Method | Sets the default printer to the remote printer specified.
Skip Method | Skips a specified number of characters when reading an input stream.
SkipLineMethod | Skips the next line when reading an input stream.
Sleep Method | Places the script process into an inactive state for the number of milliseconds specified and then continues execution.
Write Method | Writes a specified string to an output stream.
WriteBlankLines Method | Writes a specified number of newline characters to an output stream.
WriteLine Method | Writes a specified string and newline character to an output stream.
Language Element | Description
WScript Object | Exposes properties that tell the path of the running scripting host (wscript.exe or cscript.exe), its arguments, and the working mode (interactive or batch). The WScript object also provides methods to create and read objects.
WshArguments Object | Returns a pointer to the collection of command-line parameters.
WshEnvironment Object | Retrieves the system environment variables.
WshNetwork Object | Maps the network, making it easy to connect and disconnect remote drives and printers.
WshShell Object | Starts a new process and creates shortcuts, and provides the Environment collection to handle environmental variables such as WINDIR, PATH, or PROMPT.
WshShortcut Object | Creates an object reference to a shortcut.
WshSpecialFolders Object | Accesses the Windows shell folders such as the desktop folder, the Start menu folder, and the personal document folder.
WshUrlShortcut Object | Creates an object reference to URLshortcut.
Language Element | Description
Application Property | Provides the IDispatch interface on the WScript object.
Arguments Property | Returns a pointer to the WshArguments collection or identifies arguments for the shortcut.
AtEndOfLine Property | Returns True if the stream pointer immediately precedes the end-of-line marker in an input stream; False if it is not.
AtEndOfStream Property | Returns True if the stream pointer is at the end of an input stream; False if it is not.
Column Property | Returns the column number of the current character position in an input stream.
ComputerName Property | Provides a string representation of the computer name.
Count Property | Returns the number of enumerated items.
Description Property | Provides a description of a shortcut object.
Environment Property | Returns the WshEnvironment object.
FullName Property | Returns a string containing the full path to the host executable or shortcut object.
HotKey Property | Provides the hotkey of a shortcut object.
IconLocation Property | Provides the icon location of a shortcut object.
Item Property | Returns a specified item from a collection.
Length Property | Returns the number of enumerated items.
Line Property | Returns the current line number in an input stream.
Name Property | Provides a string containing the friendly name of the WScript object.
Path Property | Provides a string containing the name of the directory where WScript.Exe or CScript.Exe resides.
ScriptFullName Property | Provides the full path to the script being run.
ScriptName Property | Provides the file name of the script being run.
SpecialFolders Property | Provides the WshSpecialFolders object for accessing Windows shell folders such as the desktop folder, the Start menu folder, and the personal document folder.
StdErr Property | Exposes the write-only error output stream for the current script.
StdIn Property | Exposes the read-only input stream for the current script.
StdOut Property | Exposes the write-only output stream for the current script.
TargetPath Property | Sets the path of the file to execute of a shortcut object.
UserDomain Property | Provides a string representation of the user domain name.
UserName Property | Provides a string representation of the user name.
Version Property | Returns the version of the Windows Script Host.
WindowStyle Property | Provides the window style of a shortcut object.
WorkingDirectory Property | Provides the working directory of a shortcut object.

© 1999 Microsoft Corporation. All rights reserved.


Elements

Elements 		WSH Reference

<?job ?> Element
<?XML ?> Element
<job> Element
<object> Element
<package> Element
<reference> Element
<resource> Element
<script> Element


Windows Script Host Error Messages

Windows Script Host Error Messages 		WSH Reference

Error Message | Possible Cause
The shortcut path name must end with .lnk or .url. | Attempting to create a shortcut with a bad file extension.
There is no printer called ""%1"". | Bad printer name in SetDefaultPrinter.
Unable to remove environment variable ""%1"". | Calling Environment .Remove on a nonexistent environment variable.
Unable to remove registry key ""%1"". | Calling RegDelete on a nonexistent registry key.
Invalid root in registry key ""%1"". | Calling RegRead or RegWrite on an invalid registry key.
Unable to open registry key ""%1"" for reading. | Calling RegRead on a nonexistent registry key.
Unable to write to wsh.log. Please check with your administrator. | Calling LogEvent on Win9x when the %windir%\wsh.log file is locked.
Unable to save shortcut ""%1"". | Attempting to save a shortcut or a URL shortcut that already exists and is read-only.
Protocol handler for ""%1"" failed to execute. | Attempting to set a URL shortcut target to an improperly registered protocol handler.
Invalid syntax in URL: ""%1"". | Attempting to set a URL shortcut target to a misspelled URL.
Protocol handler for ""%1"" not found. | Attempting to set a URL shortcut target to a URL with a nonexistent protocol handler.
Unable to execute - argument list is too long. | Too many items dropped on a script file during a drag and drop operation.
Unable to wait for process. | Waiting on a process that cannot be waited on, such as waiting for the result from running a shortcut link.


Methods

Methods 		WSH Reference

AddPrinterConnection Method
AddWindowsPrinterConnection Method
AppActivate Method
Close Method
ConnectObject Method
CreateObject Method
CreateShortcut Method
DisconnectObject Method
Echo Method
EnumNetworkDrives Method
EnumPrinterConnections Method
ExpandEnvironmentStrings Method
GetObject Method
getResource Method
LogEvent Method
MapNetworkDrive Method
Popup Method
Quit Method
Read Method
ReadAll Method
ReadLine Method
RegDelete Method
RegRead Method
RegWrite Method
Remove Method
RemoveNetworkDrive Method
RemovePrinterConnection Method
Run Method
Save Method
SendKeys Method
SetDefaultPrinter Method
Skip Method
SkipLineMethod
Sleep Method
Write Method
WriteBlankLines Method
WriteLine Method


Objects

Objects 		WSH Reference

WScript Object
WshArguments Object
WshEnvironment Object
WshNetwork Object
WshShell Object
WshShortcut Object
WshSpecialFolders Object
WshUrlShortcut Object


Properties

Properties 		WSH Reference

Application Property
Arguments Property
AtEndOfLine Property
AtEndOfStream Property
Column Property
ComputerName Property
Count Property
Description Property
Environment Property
FullName Property
Hotkey Property
IconLocation Property
Item Property
Length Property
Line Property
Name Property
Path Property
ScriptFullName Property
ScriptName Property
SpecialFolders Property
StdErr Property
StdIn Property
StdOut Property
TargetPath Property
UserDomain Property
UserName Property
Version Property
WindowStyle Property
WorkingDirectory Property


WSH Version Information

Version Information 		WSH Reference

The following table lists the version of Windows Script Host implemented by Microsoft host applications.

Host Application | WSH Version
1.0 | 2.0
Microsoft Windows 98 | x
Microsoft Windows NT 4 Option Pack | x
Microsoft Windows 2000 | x

The following table lists Windows Script Host language elements and the version in which they were introduced.

Element | Version First Introduced
1.0 | 2.0
<?job ?> Element | x
<?XML ?> Element | x
AddPrinterConnection Method | x
AddWindowsPrinterConnection Method | x
AppActivate Method | x
Application Property | x
Arguments Property | x
AtEndOfLine Property | x
AtEndOfStream Property | x
Close Method | x
Column Property | x
ComputerName Property | x
ConnectObject Method | x
Count Property | x
CreateObject Method | x
CreateShortcut Method | x
Description Property | x
DisconnectObject Method | x
Echo Method | x
EnumNetworkDrives Method | x
EnumPrinterConnections Method | x
Environment Property | x
ExpandEnvironmentStrings Method | x
FullName Property | x
GetObject Method | x
getResource Method | x
HotKey Property | x
IconLocation Property | x
Item Property | x
<job> Element | x
Length Property | x
Line Property | x
LogEvent Method | x
MapNetworkDrive Method | x
Name Property | x
<object> Element | x
<package> Element | x
Path Property | x
Popup Method | x
Quit Method | x
Read Method | x
ReadAll Method | x
ReadLine Method | x
<reference> Element | x
RegDelete Method | x
RegRead Method | x
RegWrite Method | x
Remove Method | x
RemoveNetworkDrive Method | x
RemovePrinterConnection Method | x
<resource> Element | x
Run Method | x
Save Method | x
<script> Element | x
ScriptFullName Property | x
ScriptName Property | x
SendKeys Method | x
SetDefaultPrinter Method | x
Skip Method | x
SkipLine Method | x
Sleep Method | x
SpecialFolders Property | x
StdErr Property | x
StdIn Property | x
StdOut Property | x
TargetPath Property | x
UserDomain Property | x
UserName Property | x
Version Property | x
WindowStyle Property | x
WorkingDirectory Property | x
Write Method | x
WriteBlankLines Method | x
WriteLine Method | x
WScript Object | x
WshArguments Object | x
WshEnvironment Object | x
WshNetwork Object | x
WshShell Object | x
WshShortcut Object | x
WshSpecialFolders Object | x
WshUrlShortcut Object | x


Copyright

Information in this document is subject to change without notice. The names of companies, products, people, characters, and/or data mentioned herein are fictitious and are in no way intended to represent any real individual, company, product, or event, unless otherwise noted. Complying with all applicable copyright laws is the responsibility of the user. No part of this document may be reproduced or transmitted in any form or by any means, electronic or mechanical, for any purpose, without the express written permission of Microsoft Corporation.

Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual property rights covering subject matter in this document. Except as expressly provided in any written license agreement from Microsoft, the furnishing of this document does not give you any license to these patents, trademarks, copyrights, or other intellectual property.

© 1991-1999 Microsoft Corporation. All rights reserved.

Microsoft, MS, MS-DOS, ActiveX, JScript, Microsoft Press, Visual Basic, Windows, Windows NT, Win32, and Win32s are either registered trademarks or trademarks of Microsoft Corporation in the U.S.A. and/or other countries.

Other product and company names mentioned herein may be the trademarks of their respective owners.


<job> Element

<job> Element 		WSH Reference
Version 2

Description
Allows multiple jobs to be defined in a single file. Because this is an enclosing tag, every tag within the Job tag will apply to that job.
Syntax
<job [id=JobID]>
job code
</job>
Parameters
Part | Description
JobID | Optional. The unique (to the file) identifier of the job.
Example
The following example incorporates two jobs into one .wsf file using two different scripting languages:
<package>

<job id="DoneInVBS">
<?job debug="true"?>
<script language="VBScript">
    WScript.Echo "This is VBScript"
</script>
</job>

<job id="DoneInJS">
<?job debug="true"?>
<script language="JScript">
    WScript.Echo("This is JScript");
</script>
</job>

</package>


<object> Element

<object> Element 		WSH Reference
Version 2

Description
XML element used in Windows Script component files that defines objects that can be referenced by script.
Syntax
<object id="objID" [classid="clsid:GUID" | progid="progID"] />

Parameters
Part | Description
objID A name by which the object can be referenced in your script. Object ID values must begin with a letter and can include letters, digits, and underscores (_). The object ID must be unique throughout the scope of the Windows Script Component. For example, if you specify the name CObj, you can reference the object in your script as follows:
x = CObj.Prop1
GUID (Optional) A reference to the class ID (GUID) under which the object has been registered. Use "clsid:" followed by the class ID (without braces). You must specify either a classid or a progid attribute, as in the following example:
classid="clsid:2154c700-9253-11d1-a3ac-0aa0044eb5f"
progID | (Optional) The program ID of the object, which can be specified as an alternative to the class ID. You must specify either a classid or a progid attribute.
Remarks
The <object> element provides a way to expose objects globally for use in scripting within the Windows Script Component without using functions such as CreateObject(). Using an <object> element makes the object available with global scope and enables scripting tools to provide statement completion for the object's members.


<package> Element

<package> Element 		WSH Reference
Version 2

Description
Encloses multiple job definitions in a Windows Script Host control (.wsf) file.
Syntax
<package>
code for one or more jobs
</package>
Remarks
The <package> element is optional when a .wsf file contains only one job.
Example
The following example incorporates two jobs into one .wsf file using two different scripting languages:
<package>

<job id="DoneInVBS">
<?job debug="true"?>
<script language="VBScript">
    WScript.Echo "This is VBScript"
</script>
</job>

<job id="DoneInJS">
<?job debug="true"?>
<script language="JScript">
    WScript.Echo("This is JScript");
</script>
</job>

</package>


<reference> Element

<reference> Element 		WSH Reference
Version 2

Description
XML element that includes a reference to an external type library.
Syntax
<reference [object="progID"|guid="typelibGUID"] [version="version"] />

Parameters
Part | Description
progID | The program ID from which the type library can be derived. It can include either a version number (for example, ADO.Recordset.2.0), the explicit program ID of a type library, or the program ID of the executable (such as a .DLL) that incorporates the type library. If you use the object attribute, you do need not specify a version attribute, because the version can be inferred from the program ID. If the object attribute is specified, you cannot also specify a guid attribute.
typelibGUID | The GUID of the type library to reference. If the guid attribute is specified, you cannot also specify an object attribute.
version | (Optional) The version number of the type library to use. It must be in the form <major version>[.<minor version>]. If a version is not specified, the default version is 1.0. If the object attribute is used to specify the type library and the version is not specified, the version is derived from the Registry key for the specified program ID. If none can be found, the default is 1.0.
Remarks
Referencing a type library in your Windows Script Component enables you to use constants defined in the type library in scripts. The <reference> element looks up and makes available the type library associated with a specific program ID or type library name. Type library information can be available in .tlb, .olb, or .dll files.

Error Values
The WSH run-time engine can return one of the following typelib-related error messages:

Error | Description | Reason
WSH 0201: Invalid type library specification | The TYPELIB tag contains an invalid type library specification. | Typelib is corrupt.
WSH 0202: Type library cannot be loaded | Windows Script Host cannot load the type library specified in the TYPELIB tag. | Cannot find/load the typelib.
WSH 0203:Type library cannot be wrapped | Windows Script Host cannot create a Type Library Wrapper object from the type libraries specified in the TYPELIB tag. | Other.


<resource> Element

<resource> Element 		WSH Reference
Version 2

Description
XML element that isolates textual or numeric data that should not be hard-coded into a script.
Syntax
<resource id="resourceID">
text or number
</resource>
Parameters
Part | Description
resourceID | A unique identifier for the resource within the script.
Remarks
The <resource> element allows you to isolate strings or numbers in your Windows script file that you want to reference in your scripts. For example, resource elements typically are used to maintain strings that may be localized into other languages.

To get the value of a resource, call the getResource method, passing it the ID of the resource you want to use.

Example
The following code fragment defines a resource (errNonNumeric) and returns its value if the variable upperBound is not numeric.
<resource id="errNonNumeric">
    Non-numeric value passed
</resource>

<script language="VBScript">
<![CDATA[
Function getRandomNumber(upperBound)
    If IsNumeric(upperBound) Then
        getRandomNumber = CInt(upperBound * Rnd + 1)
    Else
        getRandomNumber=getResource("errNonNumeric")
    End If
End Function
]]>
</script>


<script> Element

<script> Element 		WSH Reference
Version 2

Description
XML element that contains script to define the behavior of a Windows Script component.
Syntax
<script language="language" [src="strFile"]>
script here
</script>
Parameters
Part | Description
language | The name of the scripting language used in the Windows Script component file, such as Microsoft Visual Basic® Scripting Edition (VBScript) or Microsoft JScript®.
strFile | The name of the script file to include into the <script> block.
Remarks
If XML validation is not enabled, the XML parser ignores all lines inside the <script> element. However, if XML validation is enabled by including the <?XML ?> declaration at the top of the script component file, the XML parser can misinterpret greater than (>), less than (<), and other symbols used in script as XML delimiters.

If you are creating a file that conforms closely to XML syntax, you must ensure that characters in your script element are not treated as XML-reserved characters. To do this, enclose the actual script in a <![CDATA[ ... ]]> section.

Note: Do not include a CDATA section unless you also include the <?XML ?> declaration.

Example
The following example incorporates two jobs into one .wsf file using two different scripting languages:
<package>

<job id="DoneInVBS">
<?job debug="true"?>
<script language="VBScript">
    WScript.Echo "This is VBScript"
</script>
</job>

<job id="DoneInJS">
<?job debug="true"?>
<script language="JScript">
    WScript.Echo("This is JScript");
</script>
</job>

</package>


<?XML ?> Element

<?XML ?>
Element 		WSH Reference
Version 2

Description
Indicates that a file should be parsed as XML.
Syntax
<?XML version="version" [standalone="DTDflag"] ?>
Parameters
Part | Description
version | A string in the form n.n specifying the XML level of the file. Use the value 1.0.
DTDflag | Optional. A Boolean value indicating whether the XML file includes a reference to an external Document Type Definition (DTD). Script component XML files do not include such a reference, so the value for this attribute is always "yes."
Remarks
This declaration must be the first element in the file, and cannot be preceded by any blank lines.

The existence of this declaration puts the script component compiler into strict XML mode, where element types and attribute names are case-sensitive, attribute values are enclosed in single or double quotation marks, and all elements are parsed. If the declaration is not included, the compiler allows syntax that is less strict.

You should include this declaration and follow XML conventions if your script component file will be edited in an editor that supports XML.

Example
<?XML version="1.0" standalone="yes" ?>


<?job ?> Element

<?job ?>
Element 		WSH Reference
Version 2

Description
XML processing instruction that specifies attributes for error handling.
Syntax
<?job error="flag" debug="flag" ?>
Parameters
Part | Description
error, debug | A Boolean value: "true" or "false," 1 or 0, or "yes" or "no." "False" is the default value for all attributes.
Remarks
Although most batch files normally run silently during production, you might find it useful to be notified of errors in the Windows Script Component file as you are developing it. You can specify the following types of error notifications:

Attribute | Description
error | Set to "true" to allow error messages for syntax or run-time errors in the Windows Script file.
debug | Set to "true" to enable debugging. If debugging is not enabled, you will be unable to launch the script debugger for a WSH batch file.

Example
The following example incorporates two jobs into one .wsf file using two different scripting languages:
<package>

<job id="DoneInVBS">
<?job debug="true"?>
<script language="VBScript">
    WScript.Echo "This is VBScript"
</script>
</job>

<job id="DoneInJS">
<?job debug="true"?>
<script language="JScript">
    WScript.Echo("This is JScript");
</script>
</job>

</package>


Microsoft Windows Script Host Reference

Windows Script Host Reference 		WSH Tutorial
Version Information

Alphabetic
Keyword List
Elements

Errors

Methods

Objects

Properties

© 1998 Microsoft Corporation. All rights reserved.


AddPrinterConnection Method

AddPrinterConnection Method 		WSH Reference
Version 1

See Also Applies To

Description
Maps the remote printer specified by strRemoteName to the local resource name strLocalName.
Syntax
object.AddPrinterConnection strLocalName, strRemoteName[,bUpdateProfile][,strUser][,strPassword]
Parameters
Part | Description
object | WshNetwork object.
strLocalName | Local printer resource.
strRemoteName | Remote printer resource.
bUpdateProfile | Optional. If bUpdateProfile is supplied and its value is TRUE, this mapping is stored in the user profile.
strUser | Optional. If you are mapping a remote printer using the credentials of someone other than current user, you can specify strUser and strPassword.
strPassword | Optional. If you are mapping a remote printer using the credentials of someone other than current user, you can specify strUser and strPassword.
Example
The following example uses the AddPrinterConnection method to connect a network printer to LPT1.
Set WshNetwork = CreateObject("WScript.Network")
WshNetwork.AddPrinterConnection "LPT1", "\\Server\Print1"


AddPrinterConnection Method

AddPrinterConnection Method
Applies To 		WSH Reference
WshNetwork Object


AddPrinterConnection Method

AddPrinterConnection Method
See Also 		WSH Reference
AddWindowsPrinterConnection Method
EnumPrinterConnections Method
RemovePrinterConnection Method
SetDefaultPrinter Method


AddWindowsPrinterConnection Method

AddWindowsPrinterConnection Method 		WSH Reference
Version 2

Applies To

Description
Adds a printer connection to Windows.
Syntax
Windows NT/Windows 2000:
object.AddWindowsPrinterConnection(strPrinterPath)

Windows 95/98:
object.AddWindowsPrinterConnection(strPrinterPath, strDriverName[,strPort])
Parameters
Part | Description
object | WshNetwork object.
strPrinterPath | Path to the printer.
strDriverName | Name of the driver to use. Required on Windows 95/98; ignored if used on Windows NT/Windows 2000.
strPort | Optional. Specifies the port to which to attach the printer on Windows 95/98. Default is LPT1. Ignored if used on Windows NT/Windows 2000.
Remarks
Using this method is the same as using the Control Panel/Printers to add a printer connection. Unlike the AddPrinterConnection method, this method allows you to create a printer connection without directing it to a specific port such as LPT1. If the connection fails, an error occurs.

In Windows 95/98 the printer driver must already be installed on the machine in order for the AddWindowsPrinterConnection method to work. If the driver is not installed Windows will return the error message "Unknown printer driver".

Example
The following example uses the AddWindowsPrinterConnection method to connect a network printer to LPT1.
Set WshNetwork = CreateObject("WScript.Network")
PrinterPath = "\\printserv\DefaultPrinter"
PrinterDriver = "Lexmark Optra S 1650"
WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver


AddWindowsPrinterConnection Method

AddWindowsPrinterConnection Method
Applies To 		WSH Reference
WshNetwork Object


AppActivate Method

AppActivate Method 		WSH Reference
Version 2

Applies To

Description
Activates an application window.
Syntax
AppActivate title
Parameters
Part | Description
title | Required. String expression specifying the title in the title bar of the application window that you want to activate. You can use the task ID returned by the Shell function in place of title to activate an application.
Remarks

The AppActivate statement changes the focus to the named application or window but does not affect whether it is maximized or minimized. Focus moves from the activated application window when the user takes some action to change the focus or closes the window. Use the Shell function to start an application and set the window style.
In determining which application to activate, title is compared to the title string of each running application. If no exact match exists, any application whose title string begins with "title" is activated. If an application still is not found, any application whose title string ends with title is activated. If more than one instance of the application named by title exists, one instance is arbitrarily activated.

Example
The following example starts the Windows calculator and performs some simple calculations.
set WshShell = CreateObject("WScript.Shell")
WshShell.Run "calc"
WScript.Sleep 100
WshShell.AppActivate "Calculator"
WScript.Sleep 100
WshShell.SendKeys "1{+}"
WScript.Sleep 500
WshShell.SendKeys "2"
WScript.Sleep 500
WshShell.SendKeys "~"
WScript.Sleep 500
WshShell.SendKeys "*3"
WScript.Sleep 500
WshShell.SendKeys "~"
WScript.Sleep 2500


AppActivate Method

AppActivate Method
Applies To 		WSH Reference
WshShell Object


Close Method

Close Method 		WSH Reference
Version 2

Applies To

Description
Closes an open stream.
Syntax
object.strStream.Close
Parameters
Part | Description
object | WScript object.
strStream | StdIn, StdOut, or StdErr property.
Remarks
The StdIn, StdOut, and StdErr properties and methods will work only when the script is run with CScript.exe. If the script is run with WScript.exe, an "Invalid Handle" error will result. For more information, see Windows Script Host Error Messages.


Close Method

Close Method
Applies To 		WSH Reference
StdErr Property
StdIn Property
StdOut Property


ConnectObject Method

ConnectObject Method 		WSH Reference
Version 2

Applies To

Description
Connects an object's event sources to functions with a given prefix.
Syntax
object.ConnectObject strObject, strPrefix
Parameters
Part | Description
object | WScript object.
strObject | Name of the object to be connected.
strPrefix | Prefix of the event function.
Remarks
The object must be capable of enumerating its own class event set.
Example
The following example instantiates a fictitious object and connects it to the script file. The script then calls the "SomeMethod" method on the object. If an event called "Event" occurs in the object, the MyEvent_Event subroutine is called.
Set MyObject = WScript.CreateObject("SomeObject")
MyObject.SomeMethod
WScript.ConnectObject MyObject, "MyEvent"

Sub MyEvent_Event(strName)
  WScript.Echo strName
End Sub

WScript.DisconnectObject MyObject


ConnectObject Method

ConnectObject Method
Applies To 		WSH Reference
WScript Object


CreateObject Method

CreateObject Method 		WSH Reference
Version 1

See Also Applies To

Description
Creates an object specified by the strProgID parameter.
Syntax
object.CreateObject(strProgID[,strPrefix])
Parameters
Part | Description
object | WScript object.
strProgID | The program ID of the object to create.
strPrefix | Optional.
Remarks
If the parameter strPrefix is specified, Windows Script Host connects the object's outgoing interface to the script file after creating the object. When the object fires an event, Windows Script Host calls a subroutine whose name consists of strPrefix and the event name. For example, if strPrefix is "MYOBJ_" and the object fires an event named "OnBegin," Windows Script Host calls the "MYOBJ_OnBegin" subroutine located in the script.

Example
The following example uses the CreateObject method to create a WshNetwork object:
Set WshNetwork = WScript.CreateObject("WScript.Network")


CreateObject Method

CreateObject Method
Applies To 		WSH Reference
WScript Object


CreateObject Method

CreateObject Method
See Also 		WSH Reference
GetObject Method
DisconnectObject Method


CreateShortcut Method

CreateShortcut Method 		WSH Reference
Version 1

See Also Applies To

Description
Creates an object reference to a shortcut or URLshortcut.
Syntax
object.CreateShortcut(strPathname)
Parameters
Part | Description
object | WshShell object.
strPathname | Path and file name of the shortcut being created.
Remarks
The CreateShortcut method creates a WshShortcut object and returns it. This method can be used to create a new shortcut or open an existing one to modify its properties. A Windows shortcut must have the extension ".lnk". If the shortcut title ends with ".url", a WshURLShortcut object is created.

Example
The following examples create a shortcut to the currently executing script and a URL shortcut to www.microsoft.com.

Set WshShell = WScript.CreateObject("WScript.Shell")
Set oShellLink = WshShell.CreateShortcut("Current Script.lnk")
oShellLink.TargetPath = WScript.ScriptFullName
oShellLink.Save

Set oUrlLink = WshShell.CreateShortcut("Microsoft Web Site.URL")
oUrlLink.TargetPath = "http://www.microsoft.com"
oUrlLink.Save


CreateShortcut Method

CreateShortcut Method
Applies To 		WSH Reference
WshShell Object


CreateShortcut Method

CreateShortcut Method
See Also 		WSH Reference
WshShortcut Object
WshUrlShortcut Object


DisconnectObject Method

DisconnectObject Method 		WSH Reference
Version 1

See Also Applies To

Description
Disconnects a previously connected object from Windows Script Host.
Syntax
object.DisconnectObject obj
Parameters
Part | Description
object | WScript object.
obj | Name of the object to be disconnected.
Remarks
If the specified object is not already connected to Windows Script Host, this method does nothing.
Example
The following example creates an instance of a fictitious object and connects it to the script file. The script then calls the "SomeMethod" method on the object. If an error called "Event" occurs in the object, the MyEvent_Event subroutine is called.
Set MyObject = WScript.CreateObject("SomeObject", "MyEvent")
MyObject.SomeMethod
Sub MyEvent_Event(strName)
  WScript.Echo strName
End Sub
WScript.DisconnectObject MyObject


DisconnectObject Method

DisconnectObject Method
Applies To 		WSH Reference
WScript Object


DisconnectObject Method

DisconnectObject Method
See Also 		WSH Reference
CreateObject Method
GetObject Method


Echo Method

Echo Method 		WSH Reference
Version 1

Applies To

Description
Sends output to a dialog box or the console.
Syntax
object.Echo [Arg1] [,Arg2] [,Arg3] ...
Parameters
Part | Description
object | WScript object.
Arg1, Arg2, Arg3 ... | List of items to be displayed.
Remarks
This method displays the output in a dialog box if the host is WScript.exe, or to the console if it is CScript.exe. Each item will be separated by a single space. Under CScript.exe a newline character is placed at the end of output. If no items are provided a blank line will be displayed.

Example
The following example outputs some numbers and some text:

WScript.Echo
WScript.Echo 1, 2, 3
WScript.Echo "Windows Script Host is cool."


Echo Method

Echo Method
Applies To 		WSH Reference
WScript Object


EnumNetworkDrives Method

EnumNetworkDrives Method 		WSH Reference
Version 1

See Also Applies To

Description
Returns the current network drive mappings.
Syntax
objDrives = object.EnumNetworkDrive
Parameters
Part | Description
object | WshNetwork object.
objDrives | Variable reference to the collection of drives.
Remarks
Items in this collection are local names and remote names. The first item in the collection is the drive letter and the second item is the network mapping. This pattern continues for all the network drives in the collection.
Example
The following example outputs the drive letters and network mappings:

Set WshNetwork = WScript.CreateObject("WScript.Network")
Set oDrives = WshNetwork.EnumNetworkDrives
For i = 0 to oDrives.Count -1
    WScript.Echo oDrives.Item(i)
Next


EnumNetworkDrives Method

EnumNetworkDrives Method
Applies To 		WSH Reference
WshNetwork Object


EnumNetworkDrives Method

EnumNetworkDrives Method
See Also 		WSH Reference
MapNetworkDrive Method
RemoveNetworkDrive Method


EnumPrinterConnections Method

EnumPrinterConnections Method 		WSH Reference
Version 1

See Also Applies To

Description
Returns the current network printer mappings.
Syntax
objPrinters = object.EnumPrinterConnections
Parameters
Part | Description
object | WshNetwork object.
objPrinters | Variable reference to the collection of printers.
Remarks
Items in this collection are local names and remote names. The first item in the collection is the port and the second item is the network mapping. This pattern continues for all the network printers in the collection.

Example
The following example outputs the printer ports and network mappings:

Set WshNetwork = WScript.CreateObject("WScript.Network")
Set oPrinters = WshNetwork.EnumPrinterConnections
For i = 0 to oPrinters.Count -1
    WScript.Echo oPrinters.Item(i)
Next


EnumPrinterConnections Method

EnumPrinterConnections Method
Applies To 		WSH Reference
WshNetwork Object


EnumPrinterConnections Method

EnumPrinterConnections Method
See Also 		WSH Reference
AddPrinterConnection Method
AddWindowsPrinterConnection Method
RemovePrinterConnection Method
SetDefaultPrinter Method


ExpandEnvironmentStrings Method

ExpandEnvironmentStrings Method 		WSH Reference
Version 1

Applies To

Description
Expands the requested environment variable from the running process and returns the result string.
Syntax
object.ExpandEnvironmentStrings(strString)
Parameters
Part | Description
object | WshShell object.
strString | Name of the environment variable to expand.
Remarks
Variables are enclosed by the "%" character. The environment variable name is not case-sensitive.
Example
The following example expands the WinDir environment variable and displays it in a message box:
set WshShell = CreateObject("WScript.Shell")
WScript.Echo "WinDir is " & WshShell.ExpandEnvironmentStrings("%WinDir%")


ExpandEnvironmentStrings Method

ExpandEnvironmentStrings Method
Applies To 		WSH Reference
WshShell Object


GetObject Method

GetObject Method 		WSH Reference
Version 1

See Also Applies To

Description
Retrieves an Automation object from a file or an object specified by the strProgID parameter.
Syntax
object.GetObject(strPathname [,strProgID], [strPrefix])
Parameters
Part | Description
object | WScript object.
strPathname | Required. The full path and name of the file containing the object to retrieve. is required.
strProgID | Optional. A string representing the object's program identifier (ProgID).
strPrefix Optional. If the parameter strPrefix is specified, Windows Script Host connects the object's outgoing interface to the script file after creating the object. When the object fires an event, Windows Script Host calls a subroutine whose name consists of strPrefix and the event name.
For example, if strPrefix is "MYOBJ_" and the object fires an event named "OnBegin," Windows Script Host calls the "MYOBJ_OnBegin" subroutine located in the script.
Remarks
Use the GetObject method when there is a current instance of the object or if you want to create the object from a file that is already loaded. If no current instance exists and if you do not want the object started from a file that is already loaded, use the CreateObject method.

If an object has registered itself as a single-instance object (for example, the Word.Basic object in Microsoft Word 7.0), only one instance of the object is created, no matter how many times CreateObject is executed. In addition, with a single-instance object, GetObject always returns the same instance when called with the zero-length string syntax (""), and it causes an error if the path parameter is omitted. You cannot use GetObject to obtain a reference to a Microsoft Visual Basic® class created with Visual Basic 4.0 or earlier.

GetObject works with all COM classes, independent of the language used to create the object.

Example
When the following code is executed, the application associated with the specified strPathname is started, and the object in the specified file is activated. If strPathname is a zero-length string (""), GetObject returns a new object instance of the specified type. If the strPathname parameter is omitted entirely, GetObject returns a currently active object of the specified type. If no object of the specified type exists, an error occurs.

Dim MyObject As Object
Set MyObject = GetObject("C:\CAD\SCHEMA.CAD")
MyApp = MyObject.Application
Some applications allow you to activate part of a file. To do this, add an exclamation point (!) to the end of the file name, and follow it with a string that identifies the part of the file you want to activate. For information on how to create this string, see the documentation for the application that created the object.

For example, in a drawing application, a drawing stored in a file might have multiple layers. You could use the following code to activate a layer within a drawing file called schema.cad:

Set LayerObject = GetObject("C:\CAD\SCHEMA.CAD!Layer3")
If you do not specify the object's class, COM determines the application to start and the object to activate according to the file name you provide. Some files, however, may support more than one class of object. For example, a drawing might support three different types of objects: an application object, a drawing object, and a toolbar object, all of which are part of the same file.

In the following example, FIGMENT is the name of a drawing application, and DRAWING is one of the object types it supports.

Dim MyObject As Object
Set MyObject = GetObject("C:\DRAWINGS\SAMPLE.DRW", "FIGMENT.DRAWING")


GetObject Method

GetObject Method
Applies To 		WSH Reference
WScript Object


GetObject Method

GetObject Method
See Also 		WSH Reference
CreateObject Method
DisconnectObject Method


getResource Method

getResource Method 		WSH Reference
Version 2

Description
Returns the value of a resource defined with the <resource> element.
Syntax
getResource(resourceID)
Parameters
Part | Description
resourceID | A unique identifier for the resource within the script.
Remarks

The <resource> element allows you to isolate strings or numbers in your Windows script file that you want to reference in your scripts. For example, resource elements typically are used to maintain strings that may be localized into other languages. You can use the getResource method in the script to extract the contents of a <resource> element.

Example
The following code fragment defines a resource (errNonNumeric) and returns its value if the variable upperBound is not numeric.
<resource id="errNonNumeric">
    Non-numeric value passed
</resource>

<script language="VBScript">
<![CDATA[
Function getRandomNumber(upperBound)
    If IsNumeric(upperBound) Then
        getRandomNumber = CInt(upperBound * Rnd + 1)
    Else
        getRandomNumber=getResource("errNonNumeric")
    End If
End Function
]]>
</script>


LogEvent Method

LogEvent Method 		WSH Reference
Version 2

Applies To

Description
Logs an event in the Windows NT event log or WSH.log file.
Syntax
object.LogEvent(intType, strMessage [,strTarget])
Parameters
Part | Description
object | WshShell object.
intType | Number representing the type of the event.
strMessage | The text of the log entry.
strTarget | Optional, Windows NT only. The name of the system where the event should be logged. Default is local system. Parameter is ignored on Windows 9x.
Remarks
LogEvent types may be one of the following:
Type | Value
0 | SUCCESS
1 | ERROR
2 | WARNING
4 | INFORMATION
8 | AUDIT_SUCCESS
16 | AUDIT_FAILURE

On Windows NT: Logs an event in the Windows NT event log.

On Windows 9x: Logs an event in WSH.log, which will be in the users Windows directory. The WSH.log file will contain a time stamp, the event type, and the text of the log entry.

Returns true if the event is successfully logged, otherwise returns false.
Example
The following example logs if a logon was successful or not:
Set WshShell = WScript.CreateObject("WScript.Shell")
rc = runLoginScript()	'Returns true if logon succeeds
if rc then
    WshShell.LogEvent 0, "Logon Script Completed Successfully"
else
    WshShell.LogEvent 1, "Logon Script failed"
end if


LogEvent Method

LogEvent Method
Applies To 		WSH Reference
WshShell Object


MapNetworkDrive Method

MapNetworkDrive Method 		WSH Reference
Version 1

See Also Applies To

Description
Maps the share point specified by strRemoteName to the local resource name strLocalName.
Syntax
object.MapNetworkDrive strLocalName, strRemoteName, [bUpdateProfile], [strUser], [strPassword]
Parameters
Part | Description
object | WshNetwork object.
strLocalName | Local resource name.
strRemoteName | Remote share to map.
bUpdateProfile | Optional. If bUpdateProfile is supplied and its value is TRUE, the mapping is stored in the user profile. The default is FALSE.
strUser, strPassword | Optional. If you are mapping the share point using the credentials of someone other than current user, you can specify strUser and strPassword.
Example
The following example shows how to map the "Z" drive to a network share:
Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.MapNetworkDrive "Z:", "\\Server\Share"


MapNetworkDrive Method

MapNetworkDrive Method
Applies To 		WSH Reference
WshNetwork Object


MapNetworkDrive Method

MapNetworkDrive Method
See Also 		WSH Reference
EnumNetworkDrives Method
RemoveNetworkDrive Method


Popup Method

Popup Method 		WSH Reference
Version 1

See Also Applies To

Description
Displays a pop-up message box window that contains the message contained in strText.
Syntax
intButton = object.Popup(strText, [natSecondsToWait], [strTitle], [natType])
Parameters
Part | Description
object | WshShell object.
strText | The text to appear in the pop-up window.
natSecondsToWait | Optional. The number of seconds to wait before closing the pop-up window.
strTitle | Optional. The text to appear in the title of the pop-up window.
natType | Optional. The type of buttons and icons to display in the pop-up window.
Remarks
The window title of this message box is specified by strTitle. If strTitle is omitted, the window title is "Windows Script Host."

If natSecondsToWait is supplied and its value is greater than zero, the message box window will be closed after natSecondsToWait seconds.

The meaning of natType is the same as in the Microsoft Win32® application programming interface MessageBox function. The following tables show the values and their meanings. You can combine values in these tables.

Button Types

Value | Description
0 | Show OK button.
1 | Show OK and Cancel buttons.
2 | Show Abort, Retry, and Ignore buttons.
3 | Show Yes, No, and Cancel buttons.
4 | Show Yes and No buttons.
5 | Show Retry and Cancel buttons.

Icon Types

Value | Description
16 | Show "Stop Mark" icon.
32 | Show "Question Mark" icon.
48 | Show "Exclamation Mark" icon.
64 | Show "Information Mark" icon.

The previous two tables do not cover all values for natType. For a complete list, see the Microsoft Win32 documentation.

The return value intButton denotes the number of the button that the user clicked. If the user does not click a button before natSecondsToWait seconds, intButton is set to -1.

Value | Description
1 | OK button
2 | Cancel button
3 | Abort button
4 | Retry button
5 | Ignore button
6 | Yes button
7 | No button

Example
The following example generates a simple pop-up window:
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Popup "Where do you want to go today?"


Popup Method

Popup Method
Applies To 		WSH Reference
WshShell Object


Popup Method

Popup Method
See Also 		WSH Reference
Echo Method


Quit Method

Quit Method 		WSH Reference
Version 1

Applies To

Description
Quits execution with a specified error code.
Syntax
object.Quit [intErrorCode]
Parameters
Part | Description
object | WScript object.
intErrorCode | Optional. If this parameter is included, WScript returns it as the process exit code. If intErrorCode is omitted, WScript returns zero (0) as the process exit code.
Example
The following example quits execution and returns an error code of 1:
WScript.Quit 1


Quit Method

Quit Method
Applies To 		WSH Reference
WScript Object


Read Method

Read Method 		WSH Reference
Version 2

Applies To

Description
Reads a specified number of characters from an input stream and returns the resulting string.
Syntax
object.strStream.Read(characters)
Parameters
Part | Description
object | WScript object.
strStream | StdIn property.
characters | Number of characters you want to read from the stream.
Remarks
The StdIn, StdOut and StdErr properties and methods will only work when running the script with CScript.exe. An "Invalid Handle" error will be returned when run with WScript.exe.


Read Method

Read Method
Applies To 		WSH Reference
StdIn Property


ReadAll Method

ReadAll Method 		WSH Reference
Version 2

Applies To

Description
Reads an entire input stream and returns the resulting string.
Syntax
object.strStream.ReadAll
Parameters
Part | Description
object | WScript object.
strStream | StdIn property.
Remarks
The StdIn, StdOut and StdErr properties and methods will only work when running the script with CScript.exe. An "Invalid Handle" error will be returned when run with WScript.exe.


ReadAll Method

ReadAll Method
Applies To 		WSH Reference
StdIn Property


ReadLine Method

ReadLine Method 		WSH Reference
Version 2

Applies To

Description
Reads an entire line (up to, but not including, the newline character) from an input stream and returns the resulting string.
Syntax
object.strStream.ReadLine
Parameters
Part | Description
object | WScript object.
strStream | StdIn property.
Remarks
The StdIn, StdOut and StdErr properties and methods will only work when running the script with CScript.exe. An "Invalid Handle" error will be returned when run with WScript.exe.


ReadLine Method

ReadLine Method
Applies To 		WSH Reference
StdIn Property


RegDelete Method

RegDelete Method 		WSH Reference
Version 1

See Also Applies To

Description
Deletes from the registry the key or value named by strName.
Syntax
object.RegDelete strName
Parameters
Part | Description
object | WshShell object.
strName | Key or value name to delete.
Remarks
If strName ends with a backslash character (\), this method deletes the key instead of the value. The strName parameter must begin with one of following root key names:

Short | Long
HKCU | HKEY_CURRENT_USER
HKLM | HKEY_LOCAL_MACHINE
HKCR | HKEY_CLASSES_ROOT
HKEY_USERS
HKEY_CURRENT_CONFIG

Example
The following example deletes a value and a key from the registry:
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.RegDelete "HKCU\ScriptEngine\Value" ' Delete value "Value".
WshShell.RegDelete "HKCU\ScriptEngine\Key\"  ' Delete key "Key".


RegDelete Method

RegDelete Method
Applies To 		WSH Reference
WshShell Object


RegDelete Method

RegDelete Method
See Also 		WSH Reference
RegRead Method
RegWrite Method


RegRead Method

RegRead Method 		WSH Reference
Version 1

See Also Applies To

Description
Returns the registry key or value named by strName.
Syntax
object.RegRead(strName)
Parameters
Part | Description
object | WshShell object.
strName | Key or value name to read.
Remarks
If strName ends with the backslash character (\), this method returns the key instead of the value. StrName must begin with one of following root key names:

Short | Long
HKCU | HKEY_CURRENT_USER
HKLM | HKEY_LOCAL_MACHINE
HKCR | HKEY_CLASSES_ROOT
HKEY_USERS
HKEY_CURRENT_CONFIG

The RegRead method supports only REG_SZ, REG_EXPAND_SZ, REG_DWORD, REG_BINARY, and REG_MULTI_SZ data types. If the registry has other data types, RegRead returns DISP_E_TYPEMISMATCH.

Example
The following example reads a value and key from the registry:
Set WshShell = WScript.CreateObject("WScript.Shell")
WScript.Echo WshShell.RegRead("HKCU\ScriptEngine\Val")  ' Read from value "Val".
WScript.Echo WshShell.RegRead("HKCU\ScriptEngine\Key\") ' Read from key "Key".


RegRead Method

RegRead Method
Applies To 		WSH Reference
WshShell Object


RegRead Method

RegRead Method
See Also 		WSH Reference
RegDelete Method
RegWrite Method


RegWrite Method

RegWrite Method 		WSH Reference
Version 1

See Also Applies To

Description
Sets the registry key or value named by strName.
Syntax
object.RegWrite strName, anyValue [,strType]
Parameters
Part | Description
object | WshShell object.
strName | Key or value name to write.
anyValue | The value to write into the key or registry value.
strType | Optional. The data type for the value being stored in the registry.
Remarks
If strName ends with the backslash character (\), this method returns the key instead of the value. StrName must begin with one of following root key names:

Short | Long
HKCU | HKEY_CURRENT_USER
HKLM | HKEY_LOCAL_MACHINE
HKCR | HKEY_CLASSES_ROOT
HKEY_USERS
HKEY_CURRENT_CONFIG

RegWrite supports strType as REG_SZ, REG_EXPAND_SZ, REG_DWORD, and REG_BINARY. If another data type is passed as strType, RegWrite returns E_INVALIDARG.

RegWrite automatically converts anyValue to a string when strType is REG_SZ or REG_EXPAND_SZ. If strType is REG_DWORD, anyValue is converted to an integer. If strType is REG_BINARY, anyValue must be an integer.

Example
The following example writes a value and key entry into the registry:
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.RegWrite "HKCU\ScriptEngine\Value", "Some string value"
WshShell.RegWrite "HKCU\ScriptEngine\Key\", 1 ,"REG_DWORD"


RegWrite Method

RegWrite Method
Applies To 		WSH Reference
WshShell Object


RegWrite Method

RegWrite Method
See Also 		WSH Reference
RegDelete Method
RegRead Method


Remove Method

Remove Method 		WSH Reference
Version 1

See Also Applies To

Description
Deletes the environment variable specified by strName.
Syntax
object.Remove(strName)
Parameters
Part | Description
object | WshEnvironment object.
strName | The name of the environment variable to delete.
Example
The following example deletes the EXAMPLE volatile environment variable and then deletes multiple variables from the User environment:
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Environment("VOLATILE").Remove("EXAMPLE")

Set WshUsrEnv = WScript.Environment("User")
WshUsrEnv.Remove("EXAMPLE_1")
WshUsrEnv.Remove("EXAMPLE_2")
WshUsrEnv.Remove("EXAMPLE_3")
WshUsrEnv.Remove("EXAMPLE_4")


Remove Method

Remove Method
Applies To 		WSH Reference
WshEnvironment Object


Remove Method

Remove Method
See Also 		WSH Reference
Environment Property


RemoveNetworkDrive Method

RemoveNetworkDrive Method 		WSH Reference
Version 1

See Also Applies To

Description
Removes the current resource connection denoted by strName.
Syntax
object.RemoveNetworkDrive strName, [bForce], [bUpdateProfile]
Parameters
Part | Description
object | WshNetwork object.
strName | The strName parameter can be either a local name or a remote name, depending on how the drive is mapped. If the drive has a mapping between a local name (drive letter) and a remote name, then strName must be set to the local name. If the network path does not have a local name (drive letter) mapping, then strName must be set to the remote name.
bForce | Optional. If bForce is supplied and its value is TRUE, this method removes the connections whether the resource is used or not.
bUpdateProfile | Optional. If bUpdateProfile is supplied and its value is TRUE, this mapping is removed from the user profile.
Remarks
The following example maps a network share to drive "Z" and removes the connection:
Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.MapNetworkDrive "Z:", "\\Server\Share"
WshNetwork.RemoveNetworkDrive "Z:"


RemoveNetworkDrive Method

RemoveNetworkDrive Method
Applies To 		WSH Reference
WshNetwork Object


RemoveNetworkDrive Method

RemoveNetworkDrive Method
See Also 		WSH Reference
EnumNetworkDrives Method
MapNetworkDrive Method


RemovePrinterConnection Method

RemovePrinterConnection Method 		WSH Reference
Version 1

See Also Applies To

Description
Removes the current resource connection denoted by strName.
Syntax
object.RemovePrinterConnection strName, [bForce], [bUpdateProfile]
Parameters
Part | Description
object | WshNetwork object.
strName | The strName parameter can be either a local name or a remote name, depending on how the printer is connected. If the printer has a mapping between a local name (for example, LPT1) and a remote name, then strName must be set to the local name. If the network path does not have a local name mapping, then strName must be set to the remote name.
bForce | Optional. If bForce is supplied and its value is TRUE, this method removes the connections whether the resource is used or not.
bUpdateProfile | Optional. If bUpdateProfile is supplied and its value is TRUE, this mapping is removed from the user profile.
Example
The following example removes a printer connection from LPT1:
Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.RemovePrinterConnection "LPT1:"


RemovePrinterConnection Method

RemovePrinterConnection Method
Applies To 		WSH Reference
WshNetwork Object


RemovePrinterConnection Method

RemovePrinterConnection Method
See Also 		WSH Reference
AddPrinterConnection Method
AddWindowsPrinterConnection Method
EnumPrinterConnections Method
SetDefaultPrinter Method


Run Method

Run Method 		WSH Reference
Version 1

Applies To

Description
Creates a new process that executes strCommand.
Syntax
object.Run (strCommand, [intWindowStyle], [bWaitOnReturn])
Parameters
Part | Description
object | WshShell object.
strCommand | Environment variables within the strCommand parameter are automatically expanded.
intWindowStyle | Optional. Sets the window style of the program being run.
bWaitOnReturn Optional. If bWaitOnReturn is not specified or FALSE, immediately returns to script execution rather than waiting for the process to end.

If bWaitOnReturn is set to TRUE, the Run method returns any error code returned by the application.

If bWaitOnReturn is not specified or is FALSE, the Run method returns an error code of 0 (zero).

Remarks
The following table lists the available settings for intWindowStyle:

intWindowStyle | Description
0 | Hides the window and activates another window.
1 | Activates and displays a window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when displaying the window for the first time.
2 | Activates the window and displays it as a minimized window.
3 | Activates the window and displays it as a maximized window.
4 | Displays a window in its most recent size and position. The active window remains active.
5 | Activates the window and displays it in its current size and position.
6 | Minimizes the specified window and activates the next top-level window in the Z order.
7 | Displays the window as a minimized window. The active window remains active.
8 | Displays the window in its current state. The active window remains active.
9 | Activates and displays the window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when restoring a minimized window.
10 | Sets the show state based on the state of the program that started the application.

Example
The following example runs Microsoft Notepad and opens the currently running script:
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run ("%windir%\notepad" & WScript.ScriptFullName)
The following example returns the error code from the executed application:
Set WshShell = WScript.CreateObject("WScript.Shell")
Return = WshShell.Run("notepad " & WScript.ScriptFullName, 1, TRUE)


Run Method

Run Method
Applies To 		WSH Reference
WshShell Object


Save Method

Save Method 		WSH Reference
Version 1

Applies To

Description
Saves a shortcut to the specified location.
Syntax
object.Save
Parameters
Part | Description
object | WshShortcut or WshUrlShortcut object.
Example
The following examples create a shortcut to the currently executing script, and a URLshortcut to www.microsoft.com.

Set WshShell = WScript.CreateObject("WScript.Shell")
Set oShellLink = WshShell.CreateShortcut("Current Script.lnk")
oShellLink.TargetPath = WScript.ScriptFullName
oShellLink.Save

Set oUrlLink = WshShell.CreateShortcut("Microsoft Web Site.URL") oUrlLink.TargetPath = "http://www.microsoft.com" oUrlLink.Save


Save Method

Save Method
Applies To 		WSH Reference
WshShortcut Object
WshUrlShortcut Object


SendKeys Method

SendKeys Method 		WSH Reference
Version 2

Applies To

Description
Sends one or more keystrokes to the active window as if typed at the keyboard.
Syntax
SendKeys string
Parameters
Part | Description
string | Required. String expression specifying the keystrokes to send.
Remarks

Each key is represented by one or more characters. To specify a single keyboard character, use the character itself. For example, to represent the letter A, use "A" for string. To represent more than one character, append each additional character to the one preceding it. To represent the letters A, B, and C, use "ABC" for string.
The plus sign (+), caret (^), percent sign (%), tilde (~), and parentheses ( ) have special meanings to SendKeys. To specify one of these characters, enclose it within braces ({}). For example, to specify the plus sign, use {+}. Brackets ([ ]) have no special meaning to SendKeys, but you must enclose them in braces. In other applications, brackets do have a special meaning that may be significant when dynamic data exchange (DDE) occurs. To specify brace characters, use {{} and {}}.

To specify characters that aren't displayed when you press a key, such as ENTER or TAB, and keys that represent actions rather than characters, use the codes shown below:

Key | Code
BACKSPACE | {BACKSPACE}, {BS}, or {BKSP}
BREAK | {BREAK}
CAPS LOCK | {CAPSLOCK}
DEL or DELETE | {DELETE} or {DEL}
DOWN ARROW | {DOWN}
END | {END}
ENTER | {ENTER}or ~
ESC | {ESC}
HELP | {HELP}
HOME | {HOME}
INS or INSERT | {INSERT} or {INS}
LEFT ARROW | {LEFT}
NUM LOCK | {NUMLOCK}
PAGE DOWN | {PGDN}
PAGE UP | {PGUP}
PRINT SCREEN | {PRTSC}
RIGHT ARROW | {RIGHT}
SCROLL LOCK | {SCROLLLOCK}
TAB | {TAB}
UP ARROW | {UP}
F1 | {F1}
F2 | {F2}
F3 | {F3}
F4 | {F4}
F5 | {F5}
F6 | {F6}
F7 | {F7}
F8 | {F8}
F9 | {F9}
F10 | {F10}
F11 | {F11}
F12 | {F12}
F13 | {F13}
F14 | {F14}
F15 | {F15}
F16 | {F16}

To specify keys combined with any combination of the SHIFT, CTRL, and ALT keys, precede the key code with one or more of the following codes:

Key Code
SHIFT +
CTRL ^
ALT %

To specify that any combination of SHIFT, CTRL, and ALT should be held down while several other keys are pressed, enclose the code for those keys in parentheses. For example, to specify to hold down SHIFT while E and C are pressed, use "+(EC)". To specify to hold down SHIFT while E is pressed, followed by C without SHIFT, use "+EC".

To specify repeating keys, use the form {key number}. You must put a space between key and number. For example, {LEFT 42} means press the LEFT ARROW key 42 times; {h 10} means press H 10 times.

Note You can't use SendKeys to send keystrokes to an application that is not designed to run in Microsoft Windows. Sendkeys also can't send the PRINT SCREEN key {PRTSC} to any application.

Example
The following example will start the Windows calculator and do some simple calculations.
set WshShell = CreateObject("WScript.Shell")
WshShell.Run "calc"
WScript.Sleep 100
WshShell.AppActivate "Calculator"
WScript.Sleep 100
WshShell.SendKeys "1{+}"
WScript.Sleep 500
WshShell.SendKeys "2"
WScript.Sleep 500
WshShell.SendKeys "~"
WScript.Sleep 500
WshShell.SendKeys "*3"
WScript.Sleep 500
WshShell.SendKeys "~"
WScript.Sleep 2500


SendKeys Method

SendKeys Method
Applies To 		WSH Reference
WshShell Object


SetDefaultPrinter Method

SetDefaultPrinter Method 		WSH Reference
Version 1

See Also Applies To

Description
Sets the default printer to the remote printer specified.
Syntax
object.SetDefaultPrinter strPrinterName
Parameters
Part | Description
object | WshNetwork object.
strPrinterName | Remote printer name to set as default, such as "\\Server\Printer1."
Example
The following example uses the AddPrinterConnection method to connect a network printer to LPT1: and then sets it as the default printer:
Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.AddPrinterConnection "LPT1:", "\\Server\Print1"
WshNetwork.SetDefaultPrinter "\\Server\Print1"


SetDefaultPrinter Method

SetDefaultPrinter Method
Applies To 		WSH Reference
WshNetwork Object


SetDefaultPrinter Method

SetDefaultPrinter Method
See Also 		WSH Reference
AddPrinterConnection Method
AddWindowsPrinterConnection Method
EnumPrinterConnections Method
RemovePrinterConnection Method


Skip Method

Skip Method 		WSH Reference
Version 2

Applies To

Description
Skips a specified number of characters when reading an input stream.
Syntax
object.strStream.Skip(characters)
Parameters
Part | Description
object | WScript object.
strStream | StdIn property.
characters | Number of characters to skip when reading an input stream.
Remarks
The StdIn, StdOut and StdErr properties and methods will only work when running the script with CScript.exe. An "Invalid Handle" error will be returned when run with WScript.exe.


Skip Method

Skip Method
Applies To 		WSH Reference
StdIn Property


SkipLine Method

SkipLine Method 		WSH Reference
Version 2

Applies To

Description
Skips the next line when reading an input stream.
Syntax
object.strStream.SkipLine
Parameters
Part | Description
object | WScript object.
strStream | StdIn property.
Remarks
The StdIn, StdOut and StdErr properties and methods will only work when running the script with CScript.exe. An "Invalid Handle" error will be returned when run with WScript.exe.


SkipLine Method

SkipLine Method
Applies To 		WSH Reference
StdIn Property


Sleep Method

Sleep Method 		WSH Reference
Version 2

Applies To

Description
Places the script process into an inactive state for the number of milliseconds specified and then continues execution.
Syntax
object.Sleep(intTime)
Parameters
Part | Description
object | WScript object.
intTime | Amount of time in milliseconds that the script process will be inactive.
Remarks
Events handled by the script will still be executed during a sleep. If the script engine times out or is otherwise interrupted the sleep will terminate immediately.
Example
The following example makes the script inactive for 5 seconds:
WScript.Echo "Started"
WScript.Sleep 5000
WScript.Echo "Finished"


Sleep Method

Sleep Method
Applies To 		WSH Reference
WScript Object


Write Method

Write Method 		WSH Reference
Version 2

Applies To

Description
Writes a specified string to an output stream.
Syntax
object.strStream.Write(strText)
Parameters
Part | Description
object | WScript object.
strStream | StdOut or StdErr property.
strText | The text you want to write to the stream.
Remarks
The StdIn, StdOut and StdErr properties and methods will only work when running the script with CScript.exe. An "Invalid Handle" error will be returned when run with WScript.exe.


Write Method

Write Method
Applies To 		WSH Reference
StdErr Property
StdOut Property


WriteBlankLines Method

WriteBlankLines Method 		WSH Reference
Version 2

Applies To

Description
Writes a specified number of newline characters to an output stream.
Syntax
object.strStream.WriteBlankLines(intLines)
Parameters
Part | Description
object | WScript object.
strStream | StdOut or StdErr property.
intLines | Number of newline characters to write to the stream.
Remarks
The StdIn, StdOut and StdErr properties and methods will only work when running the script with CScript.exe. An "Invalid Handle" error will be returned when run with WScript.exe.


WriteBlankLines Method

WriteBlankLines Method
Applies To 		WSH Reference
StdErr Property
StdOut Property


WriteLine Method

WriteLine Method 		WSH Reference
Version 2

Applies To

Description
Writes a specified string and newline character to an output stream.
Syntax
object.strStream.WriteLine([strText])
Parameters
Part | Description
object | WScript object.
strStream | StdOut or StdErr property.
strText | Optional. The text you want to write to the stream. If omitted, a newline character is written to the stream.
Remarks
The StdIn, StdOut and StdErr properties and methods will only work when running the script with CScript.exe. An "Invalid Handle" error will be returned when run with WScript.exe.


WriteLine Method

WriteLine Method
Applies To 		WSH Reference
StdErr Property
StdOut Property


WScript Object

WScript Object 		WSH Reference
Version 1

See Also Properties Methods

Description
Exposes properties that provide the path of the running scripting host (wscript.exe or cscript.exe), its arguments, and the working mode (interactive or batch). The WScript object also provides methods to create and read objects.
Example
The following example returns environment variable values using the Echo method:
Set WshShell = WScript.CreateObject( "WScript.Shell" )
WScript.Echo WshShell.Environment("Process").Item("WINDIR")
WScript.Echo WshShell.Environment("Process").Item("PATH")
WScript.Echo WshShell.Environment("Process").Item("PROMPT")
WScript.Echo WshShell.ExpandEnvironmentStrings("%WINDIR%")


Wscript Object

WScript Object
See Also 		WSH Reference
WshShell Object


Wscript Object

WScript Object
Methods 		WSH Reference
CreateObject Method
ConnectObject Method
DisconnectObject Method
Echo Method
GetObject Method
Quit Method
Sleep Method


Wscript Object

WScript Object
Properties 		WSH Reference
Application Property
Arguments Property
FullName Property
Name Property
Path Property
ScriptFullName Property
ScriptName Property
StdErr Property
StdIn Property
StdOut Property
Version Property


WshArguments Object

WshArguments Object 		WSH Reference
Version 1

See Also Properties

Description
Returns a pointer to the collection of command-line parameters.
Remarks
Not exposed; accessed through the Arguments property.

Example
The following example displays all command-line parameters in the Arguments collection:
Set objArgs = WScript.Arguments
For I = 0 to objArgs.Count - 1
  WScript.Echo objArgs(I)
Next


WshArguments Object

WshArguments Object
See Also 		WSH Reference
Arguments Property


WshArguments Object

WshArguments Object
Properties 		WSH Reference
Item Property
Count Property
Length Property


WshEnvironment Object

WshEnvironment Object 		WSH Reference
Version 1

See Also Properties Methods

Description
Retrieves the Microsoft Windows system environment variables.
Remarks
Not exposed; accessed through the Environment property.

Example
The following example retrieves the NUMBER_OF_PROCESSORS system environment variable.
Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshSysEnv = WshShell.Environment("SYSTEM")
WScript.Echo WshSysEnv("NUMBER_OF_PROCESSORS")


WshEnvironment Object

WshEnvironment Object
See Also 		WSH Reference
Environment Property


WshEnvironment Object

WshEnvironment Object
Methods 		WSH Reference
Remove Method


WshEnvironment Object

WshEnvironment Object
Properties 		WSH Reference
Item Property
Count Property
Length Property


WshNetwork Object

WshNetwork Object 		WSH Reference
Version 1

Properties Methods

Description
Exposes the Microsoft Windows network, making it easy to connect and disconnect remote drives and printers.
Example
The following example echoes the current computer name and user name:
Set objNet = WScript.CreateObject( "WScript.Network" )
WScript.Echo objNet.ComputerName & " - " & objNet.UserName


WshNetwork Object

WshNetwork Object
Methods 		WSH Reference
AddPrinterConnection Method
AddWindowsPrinterConnection Method
EnumNetworkDrives Method
EnumPrinterConnection Method
MapNetworkDrive Method
RemoveNetworkDrive Method
RemovePrinterConnection Method
SetDefaultPrinter Method


WshNetwork Object

WshNetwork Object
Properties 		WSH Reference
ComputerName Property
UserDomain Property
UserName Property


WshShell Object

WshShell Object 		WSH Reference
Version 1

Properties Methods

Description
Starts a new process, creates shortcuts, and provides the Environment collection to handle environmental variables such as WINDIR, PATH, or PROMPT.
Example
The following example returns environment variable values using the Echo method:
Set WshShell = WScript.CreateObject( "WScript.Shell" )
WScript.Echo WshShell.Environment.Item("WINDIR")
WScript.Echo WshShell.Environment.Item("PATH")
WScript.Echo WshShell.Environment.Item("PROMPT")
WScript.Echo WshShell.ExpandEnvironmentStrings("%WINDIR%")


WshShell Object

WshShell Object
Methods 		WSH Reference
AppActivate Method
CreateShortcut Method
ExpandEnvironmentStrings Method
LogEvent Method
Popup Method
RegDelete Method
RegRead Method
RegWrite Method
Run Method
SendKeys Method


WshShell Object

WshShell Object
Properties 		WSH Reference
Environment Property
SpecialFolders Property


WshShortcut Object

WshShortcut Object 		WSH Reference
Version 1

See Also Properties Methods

Description
Creates an object reference to a shortcut.
Remarks
Not exposed; accessed through the CreateShortcut method.

Example
The following example creates a shortcut to the currently executing script:
Set WshShell = WScript.CreateObject("WScript.Shell")
Set oShellLink = WshShell.CreateShortcut("Current Script.lnk")
oShellLink.TargetPath = WScript.ScriptFullName
oShellLink.Save


WshShortcut Object

WshShortcut Object
See Also 		WSH Reference
CreateShortcut Method


WshShortcut Object

WshShortcut Object
Methods 		WSH Reference
Save Method


WshShortcut Object

WshShortcut Object
Properties 		WSH Reference
Arguments Property
Description Property
FullName Property
Hotkey Property
IconLocation Property
TargetPath Property
WindowStyle Property
WorkingDirectory Property


WshSpecialFolders Object

WshSpecialFolders Object 		WSH Reference
Version 1

See Also Properties

Description
Returns the paths for Windows shell folders such as the desktop folder, Start menu folder, and personal document folder.
Remarks
Not exposed; accessed through the SpecialFolders property. Can be used to get the location of the desktop folder in order to create shortcuts on the desktop.

Example
The following example generates a message box containing the path to the desktop folder:
Set WshShell = WScript.CreateObject("WScript.Shell")
MsgBox "Your desktop is " & WshShell.SpecialFolders("Desktop")


WshSpecialFolders Object

WshSpecialFolders Object
See Also 		WSH Reference
SpecialFolders Property


WshSpecialFolders Object

WshSpecialFolders Object
Properties 		WSH Reference
Item Property
Count Property
Length Property


WshUrlShortcut Object

WshUrlShortcut Object 		WSH Reference
Version 1

See Also Properties Methods

Description
Creates an object reference to a URLshortcut.
Remarks
Not exposed; accessed through the CreateShortcut method.

Example
The following example creates a URLshortcut to www.microsoft.com:
Set WshShell = WScript.CreateObject("WScript.Shell")
Set oUrlLink = WshShell.CreateShortcut("Microsoft Web Site.URL")
oUrlLink.TargetPath = "http://www.microsoft.com"
oUrlLink.Save


WshUrlShortcut Object

WshUrlShortcut Object
See Also 		WSH Reference
CreateShortcut Method


WshUrlShortcut Object

WshUrlShortcut Object
Methods 		WSH Reference
Save Method


WshUrlShortcut Object

WshUrlShortcut Object
Properties 		WSH Reference
FullName Property
TargetPath Property


Application Property

Application Property 		WSH Reference
Version 1

Applies To

Description
Provides the IDispatch interface on the WScript object.
Syntax
object.Application
Parameter
Part | Description
object | WScript object.


Application Property

Application Property
Applies To 		WSH Reference
WScript Object


Arguments Property

Arguments Property 		WSH Reference
Version 1

Applies To

Description
Returns a pointer to the WshArguments collection or identifies arguments for the shortcut to the collection.
Syntax
object.Arguments
Parameters
Part | Description
object | WScript or WshShortcut object.
Example
The following example displays all command-line parameters in the Arguments collection:
Set objArgs = WScript.Arguments
For I = 0 to objArgs.Count - 1
  WScript.Echo objArgs(I)
Next


Arguments Property

Arguments Property
Applies To 		WSH Reference
WshShortcut Object
WScript Object
WshArguments Object


AtEndOfLine Property

AtEndOfLine Property 		WSH Reference
Version 2

Applies To

Description
Returns True if the stream pointer immediately precedes the end-of-line marker in an input stream; False if it does not.
Syntax
object.strStream.AtEndOfLine
Parameters
Part | Description
object | WScript object.
strStream | StdIn property.
Remarks
The StdIn, StdOut, and StdErr properties and methods will work only when the script is run with CScript.exe. If the script is run with WScript.exe, an "Invalid Handle" error will result. For more information, see Windows Script Host Error Messages.


AtEndOfLine Property

AtEndOfLine Property
Applies To 		WSH Reference
StdIn Property


AtEndOfStream Property

AtEndOfStream Property 		WSH Reference
Version 2

Applies To

Description
Returns True if the stream pointer is at the end of an input stream; False if it is not.
Syntax
object.strStream.AtEndOfStream
Parameters
Part | Description
object | WScript object.
strStream | StdIn property.
Remarks
The StdIn, StdOut, and StdErr properties and methods will work only when the script is run with CScript.exe. If the script is run with WScript.exe, an "Invalid Handle" error will result. For more information, see Windows Script Host Error Messages.


AtEndOfStream Property

AtEndOfStream Property
Applies To 		WSH Reference
StdIn Property


Column Property

Column Property 		WSH Reference
Version 2

Applies To

Description
Returns the column number of the current character position in an input stream.
Syntax
object.strStream.Column
Parameters
Part | Description
object | WScript object.
strStream | StdIn property.
Remarks
This property is read-only. After a newline character has been written, but before any other character is written, Column is equal to 1.

The StdIn, StdOut, and StdErr properties and methods will work only when the script is run with CScript.exe. If the script is run with WScript.exe, an "Invalid Handle" error will result. For more information, see Windows Script Host Error Messages.


Column Property

Column Property
Applies To 		WSH Reference
StdIn Property


ComputerName Property

ComputerName Property 		WSH Reference
Version 1

Applies To

Description
Provides a string representation of the computer name.
Syntax
object.ComputerName
Parameters
Part | Description
object | WshNetwork object.
Example
The following example echoes the current computer name and user name:
Set objNet = WScript.CreateObject("WScript.Network")
WScript.Echo objNet.ComputerName & " - " & objNet.UserName


ComputerName Property

ComputerName Property
Applies To 		WSH Reference
WshNetwork Object


Count Property

Count Property 		WSH Reference
Version 1

See Also Applies To

Description
Returns the number of enumerated items.
Syntax
object.Count
Parameters
Part | Description
object | The result of the EnumNetworkDrive or EnumPrinterConnections methods, or the object returned by the Arguments property.
Remarks
In JScript, the Count property is implemented as a method, not as a property (as it is in VBScript). Because of this, you must add a set of parentheses at the end of the statement when using Count in JScript, as in the following example:
objArgs.Count()
Example
The following example displays all command-line parameters in the Arguments collection:
Set objArgs = WScript.Arguments
For I = 0 to objArgs.Count - 1
  WScript.Echo objArgs(I)
Next


Count Property

Count Property
Applies To 		WSH Reference
EnumNetworkDrives Method
EnumPrinterConnections Method
Arguments Property


Count Property

Count Property
See Also 		WSH Reference
Arguments Property
Length Property


Description Property

Description Property 		WSH Reference
Version 1

Applies To

Description
Provides a description of a shortcut object.
Syntax
object.Description
Parameters
Part | Description
object | WshShortcut object.
Example
The following example creates a shortcut to the currently executing script:
Set WshShell = WScript.CreateObject("WScript.Shell")
Set oShellLink = WshShell.CreateShortcut("Current Script.lnk")
oShellLink.TargetPath = WScript.ScriptFullName
oShellLink.Description = "Currently running script."
oShellLink.Save


Description Property

Description Property
Applies To 		WSH Reference
WshShortcut Object


Environment Property

Environment Property 		WSH Reference
Version 1

See Also Applies To

Description
Returns the WshEnvironment object.
Syntax
object.Environment ([strType])
Parameters
Part | Description
object | WshShell object.
strType | Optional. Specifies where the environment variable resides.
Remarks
If strType is supplied, it specifies where the environment variable resides, with a possible value of "System," "User," "Volatile," or "Process." If strType is not supplied, this method retrieves the system environment variables in Microsoft Windows 2000 or the process environment variables in Windows 95/98. For Windows 95/98, only "Process" is supported in the strType parameter.

The following table lists some of the variables that are provided with the Windows operating system. Scripts also can get environment variables that have been set by other applications. None of these variables are available from the "Volatile" type.

Name | Description | Windows 2000 | Windows 95/98
System | User | Process | Process
NUMBER_OF_PROCESSORS | Number of processors running on the machine. | X | X
PROCESSOR_ARCHITECTURE | Processor type of the user's workstation. | X | X
PROCESSOR_IDENTIFIER | Processor ID of the user's workstation. | X | X
PROCESSOR_LEVEL | Processor level of the user's workstation. | X | X
PROCESSOR_VERSION | Processor version of the user's workstation. | X | X
OS | Operating system on the user's workstation. | X | X
COMSPEC | Executable file for the command prompt (typically cmd.exe). | X | X | X
HOMEDRIVE | Primary local drive (typically the C drive). | X
HOMEPATH | Default directory for users (Typically \users\default in Windows 2000). | X
PATH | PATH environment variable. | X | X | X | X
PATHEXT | Extensions for executable files (typically .com, .exe, .bat, or .cmd). | X | X
PROMPT | Command prompt (typically $P$G). | X | X
SYSTEMDRIVE | Local drive on which the system directory resides (typically c:\). | X
SYSTEMROOT | System directory (for example, c:\winnt). This is the same as WINDIR. | X
WINDIR | System directory (for example, c:\winnt). This is the same as SYSTEMROOT. | X | X | X
TEMP | Directory for storing temporary files (for example, c:\temp). | X | X | X
TMP | Directory for storing temporary files (for example, c:\temp). | X | X | X

Example
The following example retrieves the NUMBER_OF_PROCESSORS system environment variable:
Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshSysEnv = WshShell.Environment("SYSTEM")
WScript.Echo WshSysEnv("NUMBER_OF_PROCESSORS")


Environment Property

Environment Property
Applies To 		WSH Reference
WshShell Object


Environment Property

Environment Property
See Also 		WSH Reference
WshEnvironment Object


FullName Property

FullName Property 		WSH Reference
Version 1

See Also Applies To

Description
Returns a string containing the full path to the host executable file or shortcut object.
Syntax
object.FullName
Parameters
Part | Description
object | WScript, WshShortcut or WshUrlShortcut object.
Example
The following example returns the path of the host executable:
WScript.Echo WScript.Fullname


FullName Property

FullName Property
Applies To 		WSH Reference
WScript Object
WshShortcut Object
WshUrlShortcut Object


FullName Property

FullName Property
See Also 		WSH Reference
Path Property


Hotkey Property

Hotkey Property 		WSH Reference
Version 1

See Also Applies To

Description
Provides the hotkey of a shortcut object. A hotkey is a keyboard shortcut that starts or switches to a program.
Syntax
object.Hotkey = strHotkey
Parameters
Part | Description
object | WshShortcut object.
strHotkey | Sequence of keys to assign.
Remarks
The syntax of strHotkey is as follows, with Hotkey being case-insensitive:

Part Description
modifier "ALT+" | "CTRL+" | "SHIFT+" | "EXT+"
keyname "A" .. "Z" |
"0".. "9" |
"Back" | "Tab" | "Clear" | "Return" |
"Escape" | "Space" | "Prior" | ...

Hotkeys can activate only shortcuts located on the Windows-based desktop or the Windows Start menu.

Example
The following example creates a shortcut and assigns a hotkey to the shortcut:
Set WshShell = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")
Set oMyShortcut = WshShell.CreateShortcut(strDesktop & "\a_key.lnk")
OMyShortcut.TargetPath = "%windir%\notepad.exe"
oMyShortCut.Hotkey = "ALT+CTRL+F"
oMyShortCut.Save
WScript.Echo oMyShortCut.Hotkey


Hotkey Property

Hotkey Property
Applies To 		WSH Reference
WshShortcut Object


Hotkey Property

Hotkey Property
See Also 		WSH Reference
WshSpecialFolders Object


IconLocation Property

IconLocation Property 		WSH Reference
Version 1

Applies To

Description
Provides the icon location of a shortcut object.
Syntax
object.IconLocation = strIconLocation
Parameters
Part | Description
object | WshShortcut object.
strIconLocation | Location and index of the icon. The format of the icon location should be "Path, index".
Example
The following example creates a shortcut to the currently executing script:
Set WshShell = WScript.CreateObject("WScript.Shell")
Set oShellLink = WshShell.CreateShortcut("Current Script.lnk")
oShellLink.TargetPath = WScript.ScriptFullName
oShellLink.IconLocation = "notepad.exe, 0"
oShellLink.Save


IconLocation Property

IconLocation Property
Applies To 		WSH Reference
WshShortcut Object


Item Property

Item Property 		WSH Reference
Version 1

Applies To

Description
Returns a specified item from a collection.
Syntax
object.Item(natIndex)
Parameters
Part | Description
object | The result of the EnumNetworkDrive or EnumPrinterConnections methods, or the object returned by the Environment or SpecialFolders properties.
natIndex | Item to retrieve.
Remarks
Item is the default property for each collection. For EnumNetworkDrive and EnumPrinterConnections collections, index is an integer; for the Environment and SpecialFolders collections, index is a string.

WshShell.SpecialFolders.Item("strFolderName") returns NULL if the requested folder (strFolderName) is not available. For example, Windows 95/98 does not have an AllUsersDesktop folder, and returns NULL if strFolderName = AllUsersDesktop.

The following table lists special folders and the version of Windows in which they are provided:

Windows Special folders
Folder | Windows version
AllUsersDesktop | Windows 2000
AllUsersStartMenu | Windows 2000
AllUsersPrograms | Windows 2000
AllUsersStartup | Windows 2000
Desktop | Windows 95/98, Windows 2000
Favorites | Windows 95/98, Windows 2000
Fonts | Windows 95/98, Windows 2000
My Documents | Windows 95/98, Windows 2000
NetHood | Windows 95/98, Windows 2000
PrintHood | Windows 95/98, Windows 2000
Programs | Windows 95/98, Windows 2000
Recent | Windows 95/98, Windows 2000
SendTo | Windows 95/98, Windows 2000
Start Menu | Windows 95/98, Windows 2000
StartupB | Windows 2000
Templates | Windows 2000
Example
The following example outputs the drive letters and network mappings:

Set WshNetwork = WScript.CreateObject("WScript.Network")
Set oDrives = WshNetwork.EnumNetworkDrives
For i = 0 to oDrives.Count -1
    WScript.Echo oDrives.Item(i)
Next


Item Property

Item Property
Applies To 		WSH Reference
EnumNetworkDrive Method
EnumPrinterConnections Method
Environment Property
SpecialFolders Property


Item Property

Item Property
See Also 		WSH Reference
Arguments Property
Environment Property
SpecialFolders Property


Length Property

Length Property 		WSH Reference
Version 1

See Also Applies To

Description
Returns the number of enumerated items.
Syntax
object.length
Parameters
Part | Description
object | WshArguments, WshEnvironment, or WshSpecialFolders object.

Remarks
This property provides the same functionality as the Count property and is included for compatibility with Microsoft® JScript®.


Length Property

Length Property
Applies To 		WSH Reference
WshEnvironment Object
WshArguments Object
WshSpecialFolders Object


Length Property

Length Property
See Also 		WSH Reference
Arguments Property
Count Property


Line Property

Line Property 		WSH Reference
Version 2

Applies To

Description
Returns the current line number in an input stream.
Syntax
object.strStream.Line
Parameters
Part | Description
object | WScript object.
strStream | StdIn property.
Remarks
This property is read-only. After a stream is initially opened, and before anything is written, Line is equal to 1.

The StdIn, StdOut, and StdErr properties and methods will work only when the script is run with CScript.exe. If the script is run with WScript.exe, an "Invalid Handle" error will result. For more information, see Windows Script Host Error Messages.


Line Property

Line Property
Applies To 		WSH Reference
StdIn Property


Name Property

Name Property 		WSH Reference
Version 1

Applies To

Description
Returns a string containing the friendly name of the WScript object.
Syntax
object.Name
Parameters
Part | Description
object | WScript object.
Remarks
This is the default property and is read only.

Example
The following example shows two ways to use this property:
WScript.Echo WScript.Name
WScript.Echo WScript


Name Property

Name Property
Applies To 		WSH Reference
WScript Object


Path Property

Path Property 		WSH Reference
Version 1

See Also Applies To

Description
Provides a string containing the name of the directory where WScript.exe or CScript.exe resides.
Syntax
object.Path
Parameters
Part | Description
object | WScript object.
Example
The following example echoes the directory where the executable file resides:
WScript.Echo WScript.Path


Path Property

Path Property
Applies To 		WSH Reference
WScript Object


Path Property

Path Property
See Also 		WSH Reference
FullName Property


ScriptFullName Property

ScriptFullName Property 		WSH Reference
Version 1

See Also Applies To

Description
Provides the full path to the script currently being run.
Syntax
object.ScriptFullName
Parameters
Part | Description
object | WScript object.
Example
This example echoes the full path of the executing script:
WScript.Echo WScript.ScriptFullName


ScriptFullName Property

ScriptFullName Property
Applies To 		WSH Reference
WScript Object


ScriptFullName Property

ScriptFullName Property
See Also 		WSH Reference
ScriptName Property


ScriptName Property

ScriptName Property 		WSH Reference
Version 1

See Also Applies To

Description
Provides the file name of the script currently being run.
Syntax
object.ScriptName
Parameters
Part | Description
object | WScript object.
Example
The following example echoes the name of the script being run:
WScript.Echo WScript.ScriptName


ScriptName Property

ScriptName Property
Applies To 		WSH Reference
WScript Object


ScriptName Property

ScriptName Property
See Also 		WSH Reference
ScriptFullName Property


SpecialFolders Property

SpecialFolders Property 		WSH Reference
Version 1

See Also Applies To

Description
Provides the WshSpecialFolders object for accessing Windows shell folders such as the desktop folder, the Start menu folder, and the personal document folder.
Syntax
object.SpecialFolders(objWshSpecialFolders)
Parameters
Part | Description
object | WshShell object.
objWshSpecialFolders | The name of the special folder to return.
Remarks
Returns NULL if the requested folder (strFolderName) is not available. For example, Windows 95 does not have an AllUsersDesktop folder, and returns NULL if strFolderName = AllUsersDesktop.

The following special folders are provided with the Windows 95 and Microsoft Windows NT 4.0 operating systems:

AllUsersDesktop
AllUsersStartMenu
AllUsersPrograms
AllUsersStartup
Desktop
Favorites
Fonts
MyDocuments
NetHood
PrintHood
Programs
Recent
SendTo
StartMenu
Startup
Templates

Example
The following example accesses the desktop folder and displays its name:
Set WshShell = WScript.CreateObject("WScript.Shell")
MsgBox "Your desktop is " & WshShell.SpecialFolders("Desktop")


SpecialFolders Property

SpecialFolders Property
Applies To 		WSH Reference
WshShell Object


SpecialFolders Property

SpecialFolders Property
See Also 		WSH Reference
WshSpecialFolders Object


StdErr Property

StdErr Property 		WSH Reference
Version 2

Applies To

Description
Exposes the write-only error output stream for the current script.
Syntax
object.StdErr
Parameters
Part | Description
object | WScript object.
Remarks
The StdIn, StdOut, and StdErr properties and methods will work only when the script is run with CScript.exe. If the script is run with WScript.exe, an "Invalid Handle" error will result. For more information, see Windows Script Host Error Messages.


StdErr Property

StdErr Property
Applies To 		WSH Reference
WScript Object


StdIn Property

StdIn Property 		WSH Reference
Version 2

Applies To

Description
Exposes the read-only input stream for the current script.
Syntax
object.StdIn
Parameters
Part | Description
object | WScript object.
Remarks
The StdIn, StdOut, and StdErr properties and methods will work only when the script is run with CScript.exe. If the script is run with WScript.exe, an "Invalid Handle" error will result. For more information, see Windows Script Host Error Messages.


StdIn Property

StdIn Property
Applies To 		WSH Reference
WScript Object


StdOut Property

StdOut Property 		WSH Reference
Version 2

Applies To

Description
Exposes the write-only output stream for the current script.
Syntax
object.StdOut
Parameters
Part | Description
object | WScript object.
Remarks
The StdIn, StdOut, and StdErr properties and methods will work only when the script is run with CScript.exe. If the script is run with WScript.exe, an "Invalid Handle" error will result. For more information, see Windows Script Host Error Messages.


StdOut Property

StdOut Property
Applies To 		WSH Reference
WScript Object


TargetPath Property

TargetPath Property 		WSH Reference
Version 1

Applies To

Description
Sets the path to a shortcut object's executable file.
Syntax
object.TargetPath
Parameters
Part | Description
object | WshShortcut or WshUrlShortcut object.
Example
The following example creates a shortcut to the currently executing script and a URLshortcut to www.microsoft.com:
Set WshShell = WScript.CreateObject("WScript.Shell")
Set oShellLink = WshShell.CreateShortcut("Current Script.lnk")
oShellLink.TargetPath = WScript.ScriptFullName
oShellLink.Save
Set oUrlLink = WshShell.CreateShortcut("Microsoft Web Site.URL")
oUrlLink.TargetPath = "http://www.microsoft.com"
oUrlLink.Save


TargetPath Property

TargetPath Property
Applies To 		WSH Reference
WshShortcut Object
WshUrlShortcut Object


UserDomain Property

UserDomain Property 		WSH Reference
Version 1

Applies To

Description
Provides a string representation of the user domain name.
Syntax
object.UserDomain
Parameters
Part | Description
object | WshNetwork object.
Example
The following example echoes the current computer name and user domain:
Set objNet = WScript.CreateObject("WScript.Network")
WScript.Echo objNet.ComputerName & " - " & objNet.UserDomain


UserDomain Property

UserDomain Property
Applies To 		WSH Reference
WshNetwork Object


UserName Property

UserName Property 		WSH Reference
Version 1

Applies To

Description
Provides a string representation of the user name.
Syntax
object.UserName
Parameters
Part | Description
object | WshNetwork object.
Example
The following example echoes the current computer name and user name:
Set objNet = WScript.CreateObject("WScript.Network")
WScript.Echo objNet.ComputerName & " - " & objNet.UserName


UserName Property

UserName Property
Applies To 		WSH Reference
WshNetwork Object


Version Property

Version Property 		WSH Reference
Version 1

Applies To

Description
Returns the version of Microsoft Windows Script Host.
Syntax
object.Version
Parameters
Part | Description
object | WScript object.
Example
The following example echoes the current version of Windows Script Host:
WScript.Echo WScript.Version


Version Property

Version Property
Applies To 		WSH Reference
WScript Object


WindowStyle Property

WindowStyle Property 		WSH Reference
Version 1

Applies To

Description
Provides the window style of a shortcut object.
Syntax
object.WindowStyle = intWindowStyle
Parameters
Part | Description
object | WshShortcut object.
intWindowStyle | Sets the window style of the program being run.
Remarks
The following table lists the available settings for intWindowStyle:

intWindowStyle | Description
1 | Activates and displays a window. If the window is minimized or maximized, the system restores it to its original size and position.
3 | Activates the window and displays it as a maximized window.
7 | Minimizes the window and activates the next top-level window in the Z order.

Example
The following example creates a shortcut to the currently executing script:
Set WshShell = WScript.CreateObject("WScript.Shell")
Set oShellLink = WshShell.CreateShortcut("Current Script.lnk")
oShellLink.TargetPath = WScript.ScriptFullName
oShellLink.WindowStyle = 1
oShellLink.Save


WindowStyle Property

WindowStyle Property
Applies To 		WSH Reference
WshShortcut Object


WorkingDirectory Property

WorkingDirectory Property 		WSH Reference
Version 1

Applies To

Description
Provides the working directory of a shortcut object.
Syntax
object.WorkingDirectory = strWorkingDirectory
Parameters
Part | Description
object | WshShortcut object.
strWorkingDirectory | Directory in which the shortcut will start.
Example
The following example creates a shortcut to Microsoft Notepad:

Set WshShell = WScript.CreateObject("WScript.Shell")
Set oShellLink = WshShell.CreateShortcut("Notepad.lnk")
oShellLink.TargetPath = "notepad.exe"
oShellLink.WorkingDirectory = "c:\"
oShellLink.Save


WorkingDirectory Property

WorkingDirectory Property
Applies To 		WSH Reference
WshShortcut Object