Windows Scripting Host (WSH) is a Window administration tool built into the Windows operating system (OS). WSH can run many different scripting languages including the following:

Here are the different versions of WSH available:

Scripts are ideal for short, sequential, and non-interactive tasks. Here are some of the various stand alone scripts:

Search MSDN Microsoft for things like wsh and Basic Windows Script Host Tasks.

WSH Files

Here are some of the basic things a WSH file can do:

WScript.exe returns results to a window, whereas CScript.exe returns results to a command line. Running a WSH file by double click it will run the WScript.exe. Running a WSH file from a command line will run either WScript.exe or CScript.exe.

EG

Place the following into plain text files called zgh.wsf, zgh.js, and zgh.vbs respectively.

<package>
<job id="j1">
    <?job debug="false" error="false" ?>
    <script language="JScript" src="zgh.js" />
    <script language="VBScript">
        s = GetFreeSpace("c:")
        WScript.Echo s
    </script>
</job>
<job id="j2">
    <?job debug="false" error="false" ?>
    <script language="VBScript" src="zgh.vbs" />
    <script language="VBScript">
        s = ReportFileStatus("C:\zgh.js")
        WScript.Echo s
    </script>
</job>
</package>
function GetFreeSpace(DirPath) {
    var fs, d, s;
    fs = new ActiveXObject("Scripting.FileSystemObject");
    d = fs.GetDrive(fs.GetDriveName(DirPath));
    s = "Drive " + DirPath + " - " ;
    s += d.VolumeName;
    s += " Free Space: " + d.FreeSpace/1024 + " Kbytes";
    return s;
} 
Function ReportFileStatus(FileSpec)
    Dim fso, msg
    Set fso = CreateObject("Scripting.FileSystemObject")
    If (fso.FileExists(FileSpec)) Then
        msg = FileSpec & " exists."
    Else
        msg = FileSpec & " doesn't exist."
    End If
    ReportFileStatus = msg
End Function

Run the WSH file at a command line:

CScript zgh.wsf //job:j2 //job:j1

Jobs can be run in any order. If no job is specified, the first one is run. If the WSH file contained only one job, then the <package> element is not necessary.

EG

This is an example of a wsh that I might run at startup.

<job id="j1">
<script language="VBScript">

Dim oShell
Set oShell = WScript.CreateObject("WScript.shell")

'oShell.run "C:\WINNT\explorer"
'WScript.Sleep 3000

oShell.run """C:\Program Files\Microsoft Office\Office10\FRONTPG.EXE"" C:\Inetpub\wwwroot\pvtGH"
WScript.Sleep 14000

oShell.run """C:\Program Files\Microsoft Office\Office10\FRONTPG.EXE"" C:\Inetpub\wwwroot\wwwGH"
WScript.Sleep 8000

oShell.run """c:\Program Files\Internet Explorer\IEXPLORE.EXE"" http://www.google.com/"
WScript.Sleep 3000

oShell.run """c:\Program Files\Internet Explorer\IEXPLORE.EXE"" http://mail.yahoo.com/"
WScript.Sleep 3000

oShell.run """c:\Program Files\Internet Explorer\IEXPLORE.EXE"" http://localhost/wwwGH/Index.htm"
WScript.Sleep 3000

oShell.run """C:\WINNT\NOTEPAD.EXE"" ""C:\Documents and Settings\Administrator\Desktop\aaDesk.txt"""
WScript.Sleep 3000

Set oShell = Nothing

</script>
</job>

Page Modified: (Hand noted: 2007-09-13 18:13:28Z) (Auto noted: 2007-11-17 06:39:29Z)