VB.NET Program to Execute a DOS Batch File

Rajnilari2015
Posted by Rajnilari2015 under VB.NET category on | Points: 40 | Views : 341
Imports System.Diagnostics

Namespace ConsoleApplication1
Class Program
Private Shared Sub Main(args As String())
Dim exitCode = -1
Using proc As New Process()
'Set the working directory for the process to be started
proc.StartInfo.WorkingDirectory = "C:\"

'Set the doucment name to start
proc.StartInfo.FileName = "StartAppPool.bat"

'Execute the process
proc.Start()

'Wait for the associated process to exit
proc.WaitForExit()

'Gets the value of the associated process specified when it terminated.
exitCode = proc.ExitCode
End Using

If exitCode = 0 Then
Console.WriteLine("Batch executed successfully")
Else
Console.WriteLine("Some problem happened while executing the batch program")
End If

Console.ReadKey()
End Sub
End Class
End Namespace

Comments or Responses

Login to post response