Dim proc As New Process Try proc.StartInfo.FileName = "cmd.exe" proc.StartInfo.UseShellExecute = False proc.StartInfo.RedirectStandardInput = True proc.StartInfo.RedirectStandardOutput = True proc.StartInfo.RedirectStandardError = True proc.StartInfo.CreateNoWindow = True proc.Start() Dim dosLine As String = "ping -n 1 192.168.0.9" proc.StandardInput.WriteLine(dosLine) proc.StandardInput.WriteLine("exit") While (Not proc.HasExited) proc.WaitForExit(500) End While Dim pingResult As String = proc.StandardOutput.ReadToEnd() If pingResult <> "" Then End If proc.StandardOutput.Close() Catch ex As Exception Finally Try proc.Close() proc.Dispose() Catch ex As Exception End Try End Try
{
get
{
try
{
//检查socket的状态是否可读
if(m_socket.Connected && m_socket.Poll(0, SelectMode.SelectRead))
{
byte[] aByte = new byte[1];
//因为TCP/IP协议无法精确的判断网络是否可用
//试读一个字符,Peek参数指定读取的字符不会从缓冲区中移除
//假如可读则表示连接可用
if(m_socket.Receive(aByte, 0, 1, SocketFlags.Peek) != 0)
return true;
Close("Disconnected.");
return false;
}
}
catch(SocketException e)
{
OnException(e);
}
return m_socket.Connected;
}
}
try
{
proc.StartInfo.FileName = "cmd.exe";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardInput = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.CreateNoWindow = true;
proc.Start();
string dosLine = @"ping -n 1 " + "192.168.0.9";
proc.StandardInput.WriteLine(dosLine);
proc.StandardInput.WriteLine("exit");
while (proc.HasExited == false)
{
proc.WaitForExit(500);
}
string pingResult = proc.StandardOutput.ReadToEnd();
if (pingResult!="")
{
}
proc.StandardOutput.Close();
}
catch
{
}
finally
{
try
{
proc.Close();
proc.Dispose();
}
catch
{
}
}
Try
proc.StartInfo.FileName = "cmd.exe"
proc.StartInfo.UseShellExecute = False
proc.StartInfo.RedirectStandardInput = True
proc.StartInfo.RedirectStandardOutput = True
proc.StartInfo.RedirectStandardError = True
proc.StartInfo.CreateNoWindow = True
proc.Start()
Dim dosLine As String = "ping -n 1 192.168.0.9"
proc.StandardInput.WriteLine(dosLine)
proc.StandardInput.WriteLine("exit")
While (Not proc.HasExited)
proc.WaitForExit(500)
End While
Dim pingResult As String = proc.StandardOutput.ReadToEnd()
If pingResult <> "" Then
End If
proc.StandardOutput.Close()
Catch ex As Exception
Finally
Try
proc.Close()
proc.Dispose()
Catch ex As Exception
End Try
End Try
中可以填入你的处理