Welcome !
         

 fShellRun

Author Message
DiGiTAL.SkReAM

  • Total Posts : 1291
  • Scores: 8
  • Reward points : 0
  • Joined: 9/7/2005
  • Location: Clearwater, FL, USA
  • Status: offline
fShellRun Tuesday, February 06, 2007 3:03 AM (permalink)
0
I use this function a lot in my scripts, to capture the output/results of a dos command.  It captures the output of a dos command and returns it in a string.
 
 wscript.echo fShellRun("%comspec% /c dir c:\")
  
  
  
 Function fShellRun(sCommandStringToExecute)
 ' This function will accept a string as a DOS command to execute.
 ' It will then execute the command in a shell, and capture the output into a file.
 ' That file is then read in and its contents are returned as the value the function returns.
  Dim oShellObject, oFileSystemObject, sShellRndTmpFile
  Dim oShellOutputFileToRead, iErr
  Set oShellObject = CreateObject("Wscript.Shell")
  Set oFileSystemObject = CreateObject("Scripting.FileSystemObject")
  sShellRndTmpFile = oShellObject.ExpandEnvironmentStrings("%temp%") & oFileSystemObject.GetTempName
  On Error Resume Next 
   oShellObject.Run sCommandStringToExecute & " > " & sShellRndTmpFile, 0, True
   iErr = Err.Number
  On Error GoTo 0
   If iErr <> 0 Then 
    fShellRun = ""
    Exit Function 
   End If 
  fShellRun = oFileSystemObject.OpenTextFile(sShellRndTmpFile,1).ReadAll
  oFileSystemObject.DeleteFile sShellRndTmpFile, True 
 End Function
 

 
"Would you like to touch my monkey?" - Dieter (Mike Meyers)

"It is better to die like a tiger, than to live like a pussy."
-Master Wong, from Balls of Fury
 
#1
    Online Bookmarks Sharing: Share/Bookmark

    Jump to:

    Current active users

    There are 0 members and 3 guests.

    Icon Legend and Permission

    • New Messages
    • No New Messages
    • Hot Topic w/ New Messages
    • Hot Topic w/o New Messages
    • Locked w/ New Messages
    • Locked w/o New Messages
    • Read Message
    • Post New Thread
    • Reply to message
    • Post New Poll
    • Submit Vote
    • Post reward post
    • Delete my own posts
    • Delete my own threads
    • Rate post

    2000-2017 ASPPlayground.NET Forum Version 3.9