VB.net下用process写dos命令后怎么样关闭dos?
我用Process.Start("cmd.exe", "/k ping -n 1 127.0.0.1 >>C:\1.txt ")之后怎么样关闭dos窗口?
小弟我做的是调用ce下的ping程序以测试网络的连通情况
我先 Process.Start("cmd.exe", "/k ping -n 1 127.0.0.1 >>C:\1.txt ")把结果保存到 1.txt里然后把文本里面的信息读出来再进行搜索匹配判断。
但感觉这样麻烦了。本来我写的程序是(下面在.net framwork 下没有问题)
Public Function CmdPing(ByVal strIp As String) As String
Dim p As New Process
p.StartInfo.FileName = "cmd.exe"
p.StartInfo.UseShellExecute = False
'p.StartInfo.RedirectStandardInput = True
'p.StartInfo.RedirectStandardOutput = True
'p.StartInfo.RedirectStandardError = True
'p.StartInfo.CreateNoWindow = True
Dim pingrst As String
p.Start() '开始进程
'p.StandardInput.WriteLine("ping -n 1 " + strIp)
'p.StandardInput.WriteLine("exit")
'Dim strRst As String = p.StandardOutput.ReadToEnd()
If (strRst.IndexOf("(0% loss)") <> -1 And strRst.IndexOf("TTL=128") <> -1) Then
pingrst = "网络连接正常"
Else
pingrst = strRst
pingrst = "网络不通"
End If
p.Close()
Return pingrst
End Function
但是在.net compact framwork 下 ' 后面的句子都不支持。所以才想用Process.Start("cmd.exe", "/k ping -n 1 127.0.0.1 >>C:\1.txt ")
但不知道怎么关掉dos窗口。
请各位大大赐教。谢谢!