你可以把结果写到一个文件里再读出来啊Private Sub Command1_Click() Dim strResult As String Dim strIn As String Dim strPath As String strPath = App.Path & "\testmode.bat" Call Shell("cmd /c " & strPath & ">C:\1.txt", vbNormalFocus) Do While Dir("C:\1.txt") = "" Loop Open "C:\1.txt" For Input As #1 Do While Not EOF(1) ' 循环至文件尾。 Line Input #1, strIn ' 读入一行数据并将其赋予某变量。 strResult = strResult & strIn & vbCrLf Loop Close #1 Debug.Print strResult End Sub
使用API函数取得某个环境变量的值 Declare Function GetEnvironmentVariable Lib "kernel32" Alias "GetEnvironmentVariableA" (ByVal lpName As String, ByVal lpBuffer As String, ByVal nSize As Long) As Long
Dim strResult As String
Dim strIn As String
Dim strPath As String
strPath = App.Path & "\testmode.bat"
Call Shell("cmd /c " & strPath & ">C:\1.txt", vbNormalFocus)
Do While Dir("C:\1.txt") = ""
Loop
Open "C:\1.txt" For Input As #1
Do While Not EOF(1) ' 循环至文件尾。
Line Input #1, strIn ' 读入一行数据并将其赋予某变量。
strResult = strResult & strIn & vbCrLf
Loop
Close #1
Debug.Print strResult
End Sub
Declare Function GetEnvironmentVariable Lib "kernel32" Alias "GetEnvironmentVariableA" (ByVal lpName As String, ByVal lpBuffer As String, ByVal nSize As Long) As Long