Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to run a batch file from vb form 1

Status
Not open for further replies.

cmn2

Programmer
Mar 6, 2003
73
US
Greetings
I have an app that writes an ftp script file and also writes a batch file to execute the script file. When I double click on the batch file it runs the script file perfectly. Now I want to eliminate the double click and run the batch file automatically from my app. I am using the following line to try to accomplish this but cannot get it to work.

System.Diagnostics.Process.Start("C:\MyBatchFile.bat")

Does anyone have experience to lend on how to execute a batch file from a vb app? Thank you.

 
Hi,

when I need to launch an external file, I allways use:

Code:
  Process.Start("filePath")

hmmm.. it strangely looks like your line of code, but I don't think this (the one I use) Process class comes from the "System.Diagnostics" namespace as I don't have any reference to it in my test project.
 
A batch file is not a program file and so needs to be started slightly differently. Look at the various options under System.Diagnostics.Process - there is a parameter that you can set to force it to run a file which is of a known type. Alternatively pass your batch file as the parameter to cmd.exe in System.Diagnostics.Process


Hope this helps.

[vampire][bat]
 
I've now been able to answer this more thoroughly here:

thread796-1360713


Hope this helps.

[vampire][bat]
 
Thanks for sticking with this. I will try it out later today and will post back.
 
This is what finally worked for me. Setting the WorkingDirectory was the key. Thanks for all of your help, I appreciate it.

Dim p As New Process
p.StartInfo.WorkingDirectory = "C:\BatTest"
p.StartInfo.FileName = "c:\BatTest\MyBatchFile.bat"
p.Start()
p.WaitForExit()
p.Close()
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top