Code to execute a batch file

Please support our VB.NET advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Sep 2009
Posts: 13
Reputation: jaimca is an unknown quantity at this point 
Solved Threads: 0
jaimca jaimca is offline Offline
Newbie Poster

Code to execute a batch file

 
0
  #1
Oct 20th, 2009
Hi


I need a vb.net example code to execute a batch file when a button is clicked in my application .. The .bat file is in a different location and it must be called and executed.... Thanks in advance..
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,469
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 629
Sponsor
sknake's Avatar
sknake sknake is online now Online
.NET Enthusiast
 
1
  #2
Oct 20th, 2009
  1. Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
  2. Dim p As New System.Diagnostics.Process()
  3. p.StartInfo.FileName = "C:\\test.bat"
  4. p.Start()
  5. End Sub

You can also call p.WaitForExit() if you want your application to hold up until the bat file is done running.
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 1
Reputation: crypto256 is an unknown quantity at this point 
Solved Threads: 1
crypto256 crypto256 is offline Offline
Newbie Poster
 
1
  #3
Oct 20th, 2009
Try out this:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim p As New Process()
p.StartInfo.FileName = "E:\Users\Tom\Desktop\test.bat"
p.StartInfo.WindowStyle = ProcessWindowStyle.Normal
p.Start()
p.WaitForExit()
p.Close()
MessageBox.Show("App closed now")
End Sub
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 13
Reputation: jaimca is an unknown quantity at this point 
Solved Threads: 0
jaimca jaimca is offline Offline
Newbie Poster
 
0
  #4
Oct 20th, 2009
thanks a lot my problem was solved..
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 13
Reputation: jaimca is an unknown quantity at this point 
Solved Threads: 0
jaimca jaimca is offline Offline
Newbie Poster
 
0
  #5
Oct 20th, 2009
thanks a lot my problem was solved
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 415 | Replies: 4
Thread Tools Search this Thread



Tag cloud for VB.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC