2015年12月8日 星期二

vbnet process cmd result 回傳值

Public Function Cmd(ByVal Command As String) As String
      Dim process As New System.Diagnostics.Process()
      process.StartInfo.FileName = "C:\Windows\System32\cmd.exe"
      process.StartInfo.UseShellExecute = False
      process.StartInfo.RedirectStandardInput = True
      process.StartInfo.RedirectStandardOutput = True
      process.StartInfo.RedirectStandardError = True
      process.StartInfo.CreateNoWindow = True
      process.Start()
      process.StandardInput.WriteLine(Command)
      process.StandardInput.WriteLine("exit")
      Dim Result As String = process.StandardOutput.ReadToEnd()
      process.Close()
      Return Result
End Function


Dim result As String
result = Cmd(“ipconfig”)
Debug.Print(result)

沒有留言:

張貼留言