问题描述
我需要从visual basic 2010运行CMD命令
完全隐藏我不希望显示黑屏。
谢谢。
我尝试了什么:
试试这个:
Shell(命令)
运行命令,但显示CMD屏幕。
我需要完全隐藏和管理员级别。
任何想法?
I need run CMD command from visual basic 2010
completely hidden I do not want the black screen is displayed.
Thanks.
What I have tried:
try this:
Shell ("command")
run the command, but shows CMD screen.
and I need to completely hiden and administrator level.
Any ideas?
推荐答案
Private processCmd As Process = Nothing
Private Sub butStartCmd_Click(sender As Object, e As EventArgs) Handles butStartCmd.Click
If processCmd Is Nothing Then
Dim pCommand As New Process()
pCommand.StartInfo.FileName = "cmd"
pCommand.StartInfo.RedirectStandardOutput = True
pCommand.StartInfo.RedirectStandardError = True
pCommand.StartInfo.UseShellExecute = False
pCommand.StartInfo.CreateNoWindow = True
pCommand.Start()
processCmd = pCommand
End If
'
'int index = (int)numericUpDown1.Value;
'thumbs.DeleteAt(index);
End Sub
Private Sub butKillCmd_Click(sender As Object, e As EventArgs) Handles butKillCmd.Click
If processCmd IsNot Nothing Then
processCmd.Kill()
processCmd = Nothing
End If
End Sub
谢谢。
我把命令放在哪里?
命令是:ping 8.8.8.8 -t
为什么使用命令提示符来ping?
为什么不直接使用Ping类在你的代码?它很简单,它更容易获得和处理结果,并且你的代码更清晰......
例如:
"Thanks.
where I put the command?
the command is: ping 8.8.8.8 -t"
Why are you using a command prompt to ping?
Why not use the Ping class directly in your code? It's simple, it's easier to get and process the results, and it's a lot clearer in your code...
For example:
Private Sub PingIt()
Try
Dim p As New Ping()
Dim reply As PingReply = p.Send(IPAddress.Parse("8.8.8.8"))
Console.WriteLine("Ping: {0}:{1}:{2}", reply.Address, reply.RoundtripTime, reply.Status)
Catch pex As PingException
Console.WriteLine("Ping failed: " + pex.InnerException.Message)
End Try
End Sub
这篇关于如何从visual basic 2010运行CMD命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!