VB.net下用process写dos命令后怎么样关闭dos?

mania001 2007-06-29 03:54:01
我用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窗口。
请各位大大赐教。谢谢!
...全文
377 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
BitCoffee 2007-06-29
  • 打赏
  • 举报
回复
Dim processlist() As Process = Process.GetProcesses()
For Each kp As Process In processlist
If kp.ProcessName = "cmd" Then
kp.Kill()
End If
Next
wangsaokui 2007-06-29
  • 打赏
  • 举报
回复
Process.Start("cmd.exe","/c ping -n 1 127.0.0.1");
wangsaokui 2007-06-29
  • 打赏
  • 举报
回复
http://www.web521.com/web/565968/T651436.shtml

16,552

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧