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: ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access