Shell Object

The WSH Shell object provides the ability to create Windows shortcuts, read environment variables, manipulate registry settings, and run external programs.

To create an instance of the WSH Shell object, pass the argument Wscript.Shell to the Wscript.CreateObject method:

Set objShell = Wscript.CreateObject("Wscript.Shell")

ExpandEnvironmentVariables Method

Environment variables are information stored by the Windows operating system. You can list the environment variables currently set by executing the DOS Set command from the command prompt. You can interpolate their values into your script using the ExpandEnvironmentVariables method of a Shell object. Its syntax is:

                  strValue = objShell.ExpandEnvironmentVariables(strString)

Any strings in the strString parameter that are enclosed with % symbols will be expanded using the corresponding environment variable value.

Set objShell = Wscript.CreateObject("Wscript.shell")
Wscript.Echo _
     objShell.ExpandEnvironmentStrings( _
      "Your temp directory is %TEMP%")

Run Method

The Run method executes an external program. This can be any Windows executable or command-line program. If you don’t specify an explicit path to the application, the Run method will search the paths specified in the PATH environment variable. The following example executes Notepad:

Set objShell = Wscript.CreateObject("Wscript.shell")
objShell.Run ("Notepad.exe")

SpecialFolders Collection

The SpecialFolders collection returns the path to a specified system folder: ...

Get Windows XP in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.