'==========================================================================
'
' VBScript:  AUTHOR: Ed Wilson , MS,  8/4/2006
'
' NAME: CmdDir.vbs
'
' COMMENT: Key concepts are listed below:
'1.Using %comspec% in place of cmd or command
'2.Using the Exec method
'3.Using stdout and AtEndOfStream property
'==========================================================================
Option Explicit
Dim objShell
Dim objExec
Dim strLine
Dim dirTxt
Dim dirFile

dirFile = "ntuser.dat"
WScript.Echo("beginning " & Now)
Set objShell = WScript.CreateObject("WScript.Shell")
Set objExec = objShell.Exec("%comspec% /c dir /aH c:\*.dat /s")

Do Until objExec.StdOut.AtEndOfStream
    strLine = objExec.StdOut.ReadLine()
    dirTxt = Instr(strLine,dirFile)
    If dirTxt<> 0 Then
        WScript.Echo strLine
    End If
Loop
WScript.Echo("all done " & Now)
