
Using WSH to perform a backup
Re: Using WSH to perform a backup%Comspec% and %windir% are
environmental variables that are set by the operating system itself.
The %comspec% variable returns the path of the command interpretor
(such as c:\windows\command.com or c:\winnt\cmd.exe). The %windir%
variable returns the path of the operating system directory, which for
lack of a better definition can be described as the directory that
holds win.ini and system.ini. You or an application on your system can
create environmental variables by adding them to autoexec.bat or
config.sys in Windows '9x, or by using the Control Panel in Windows
NT.
You can see a list of all such variables on your system by typing SET
at a command prompt. Or you can use WSH to see the list. Here are two
different approaches to viewing the list.
This approach uses the Environment object.
Dim Environment
Dim Variable
Dim EnvVarList
Set Environment = CreateObject("Wscript.Shell").Environment
For Each Variable In Environment
EnvVarList = EnvVarList & Variable & vbNewLine
Next 'Variable
MsgBox EnvVarList
Approach number two pipes the Dos SET command through cscript, quits
the first instance of the script, which means that it can be run using
wscript, and then reads the list via StdIn.
Dim Shell
Set Shell = CreateObject("Wscript.Shell")
If Wscript.Arguments.Count = 0 Then
Shell.Run "%comspec% /cset|cscript """ &_
Wscript.ScriptFullName & """ 1",0,True
Wscript.Quit
End If
Shell.Popup Wscript.StdIn.ReadAll
Your help has been excellent! I was looking through my WSH books and
I can't find any information on things like %comspec% and %windir%
etc. What kind of components are these and where can I find info to
learn about them? TIA