Public
Class ConsoleOutput
Class ConsoleOutput
![](https://i-blog.csdnimg.cn/blog_migrate/1a529fe8858c8886aa6e01db8070eb7a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/2a596131bedb6917a824aff7b32d40db.gif)
Private Sub New()Sub New()
End Sub
![](https://i-blog.csdnimg.cn/blog_migrate/1a529fe8858c8886aa6e01db8070eb7a.gif)
Private Shared gWorkingDirectory As String = Environment.GetFolderPath(Environment.SpecialFolder.Personal)
![](https://i-blog.csdnimg.cn/blog_migrate/1a529fe8858c8886aa6e01db8070eb7a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/2a596131bedb6917a824aff7b32d40db.gif)
Public Shared Property WorkingDirectory()Property WorkingDirectory() As String
Get
Return gWorkingDirectory
End Get
Set(ByVal Value As String)
gWorkingDirectory = Value
End Set
End Property
![](https://i-blog.csdnimg.cn/blog_migrate/1a529fe8858c8886aa6e01db8070eb7a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/2a596131bedb6917a824aff7b32d40db.gif)
Public Shared Function ExcuteCmd()Function ExcuteCmd(ByVal command As String) As String
Dim mResult As String = ""
![](https://i-blog.csdnimg.cn/blog_migrate/1a529fe8858c8886aa6e01db8070eb7a.gif)
Dim tmpProcess As New Process
With tmpProcess
With .StartInfo
.CreateNoWindow = True
.FileName = .EnvironmentVariables.Item("ComSpec")
.RedirectStandardOutput = True
.UseShellExecute = False
.Arguments = String.Format("/C {0}", command)
.WorkingDirectory = gWorkingDirectory
End With
Try
.Start()
.WaitForExit(5000)
mResult = .StandardOutput.ReadToEnd
Catch e As System.ComponentModel.Win32Exception
mResult = e.ToString
End Try
End With
![](https://i-blog.csdnimg.cn/blog_migrate/1a529fe8858c8886aa6e01db8070eb7a.gif)
Return mResult
End Function
![](https://i-blog.csdnimg.cn/blog_migrate/1a529fe8858c8886aa6e01db8070eb7a.gif)
End Class测试:
Private
Sub Button1_Click()
Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Console.WriteLine(ConsoleOutput.ExcuteCmd("NET TIME //192.168.0.223"))
End Sub
'
结果
'
//192.168.0.223 的当前时间是 2006-3-30 9:57
'
'
命令成功完成。
![](https://i-blog.csdnimg.cn/blog_migrate/1a529fe8858c8886aa6e01db8070eb7a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/2a596131bedb6917a824aff7b32d40db.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6bff3c6dabb6abda752a92f7b5eb9220.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/695dd038868e929a8ab171b23222720a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/1a529fe8858c8886aa6e01db8070eb7a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/1a529fe8858c8886aa6e01db8070eb7a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/1a529fe8858c8886aa6e01db8070eb7a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/2a596131bedb6917a824aff7b32d40db.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6bff3c6dabb6abda752a92f7b5eb9220.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/1a529fe8858c8886aa6e01db8070eb7a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/1a529fe8858c8886aa6e01db8070eb7a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/1a529fe8858c8886aa6e01db8070eb7a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/1a529fe8858c8886aa6e01db8070eb7a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/1a529fe8858c8886aa6e01db8070eb7a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/1a529fe8858c8886aa6e01db8070eb7a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/695dd038868e929a8ab171b23222720a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/1a529fe8858c8886aa6e01db8070eb7a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/2a596131bedb6917a824aff7b32d40db.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6bff3c6dabb6abda752a92f7b5eb9220.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/1a529fe8858c8886aa6e01db8070eb7a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/1a529fe8858c8886aa6e01db8070eb7a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/1a529fe8858c8886aa6e01db8070eb7a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/1a529fe8858c8886aa6e01db8070eb7a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/1a529fe8858c8886aa6e01db8070eb7a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/1a529fe8858c8886aa6e01db8070eb7a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/1a529fe8858c8886aa6e01db8070eb7a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/1a529fe8858c8886aa6e01db8070eb7a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/1a529fe8858c8886aa6e01db8070eb7a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/1a529fe8858c8886aa6e01db8070eb7a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/1a529fe8858c8886aa6e01db8070eb7a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/1a529fe8858c8886aa6e01db8070eb7a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/1a529fe8858c8886aa6e01db8070eb7a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/1a529fe8858c8886aa6e01db8070eb7a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/1a529fe8858c8886aa6e01db8070eb7a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/1a529fe8858c8886aa6e01db8070eb7a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/1a529fe8858c8886aa6e01db8070eb7a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/1a529fe8858c8886aa6e01db8070eb7a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/1a529fe8858c8886aa6e01db8070eb7a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/1a529fe8858c8886aa6e01db8070eb7a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/1a529fe8858c8886aa6e01db8070eb7a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/1a529fe8858c8886aa6e01db8070eb7a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/695dd038868e929a8ab171b23222720a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/1a529fe8858c8886aa6e01db8070eb7a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/bfbc5bcd11195c273c0537af3d4d5e5e.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/130ae5b8f553cef9daef591fca25f9dd.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/9ca0e8045917fa637f9626c2ffde33c7.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/1a529fe8858c8886aa6e01db8070eb7a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/bfbc5bcd11195c273c0537af3d4d5e5e.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/e1d325a9544fd9655850835de9aa0988.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/e1d325a9544fd9655850835de9aa0988.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/e1d325a9544fd9655850835de9aa0988.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/e1d325a9544fd9655850835de9aa0988.gif)