run a command line from vb.net app code example
Example 1: run a command line from vb.net app
Sub systemcmd(ByVal cmd As String)
Shell("cmd /c """ & cmd & """", AppWinStyle.MinimizedFocus, True)
End Sub
Example 2: run a command line from vb.net app
Public Module Extensions
'''
''' Extension method to run string as CMD command.
'''
''' [String] Command to run.
''' [Boolean](Default:False) Option to show CMD window.
''' [Boolean](Default:False) Option to wait for CMD process to complete before exiting sub.
''' [Boolean](Default:False) Option to keep window visible after command has finished. Ignored if ShowWindow is False.
Public Sub RunCMD(command As String, Optional ShowWindow As Boolean = False, Optional WaitForProcessComplete As Boolean = False, Optional permanent As Boolean = False)
Dim p As Process = New Process()
Dim pi As ProcessStartInfo = New ProcessStartInfo()
pi.Arguments = " " + If(ShowWindow AndAlso permanent, "/K", "/C") + " " + command
pi.FileName = "cmd.exe"
pi.CreateNoWindow = Not ShowWindow
If ShowWindow Then
pi.WindowStyle = ProcessWindowStyle.Normal
Else
pi.WindowStyle = ProcessWindowStyle.Hidden
End If
p.StartInfo = pi
p.Start()
If WaitForProcessComplete Then Do Until p.HasExited : Loop
End Sub
End Module