0
votes

I am trying to run the following command and return the output of it using VBscript:

dir /A-d "C:\Windows\Minidump" | find /c "/"

And I have the following script but it does not work (probably because of " charachters:

Wscript.Echo runCMD("dir /A-d "C:\Windows\Minidump" | find /c "/"")

Function runCMD(strRunCmd)

 Set objShell = WScript.CreateObject("WScript.Shell")
 Set objExec = objShell.Exec(strRunCmd)

 strOut = ""

 Do While Not objExec.StdOut.AtEndOfStream
  strOut = strOut & objExec.StdOut.ReadLine()
 Loop

 Set objShell = Nothing
 Set objExec = Nothing

 runCMD = strOut

End Function

Any suggestions on how to achieve this?

1
Does it have to be vbscript? could you just place the following in a bat file? dir /A-d "C:\Windows\Minidump" | find /c "/" > newfile.txt - safetyOtter

1 Answers

3
votes
  1. dir is intrinsic; you need %comspec%.
  2. Double quotes need to be escaped by double double quotes in VBScript:

    Wscript.Echo runCMD("%comspec% /c dir /A-d ""C:\Windows\Minidump"" | find /c ""/""")