Created
April 18, 2010 12:01
-
-
Save pwlin/370195 to your computer and use it in GitHub Desktop.
shell exec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' wsh shell execute and return output | |
' MsgBox RunOutput("COMMAND /C DIR C:\", 0) | |
Function RunOutput(cProgram, nWindowType) | |
'-- Obtain a Temporary File Name | |
Dim oFS | |
Set oFS = CreateObject("Scripting.FileSystemObject") | |
Dim cFile | |
cFile = oFS.GetSpecialFolder(2).Path & "\" & oFS.GetTempName | |
'-- Execute the command and redirect the output to the file | |
Dim oShell | |
Set oShell = CreateObject("WScript.Shell") | |
oShell.Run cProgram & " >" & cFile, nWindowType, True | |
Set oShell = Nothing | |
'-- Read output file and return | |
Dim oFile | |
Set oFile = oFS.OpenTextFile(cFile, 1, True) | |
RunOutput = oFile.ReadAll() | |
oFile.Close | |
'-- Delete Temporary File | |
oFS.DeleteFile cFile | |
Set oFS = Nothing | |
Set cFile = Nothing | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment