简体   繁体   中英

VB.Net How to run the application in a specific folder?

So a little bit of my code is to run an application (a batch file in an external folder that the user can select.) The problem is that when I use

Path.GetDirectoryName(O.FileName) + "\\BasicStart.bat"

however when I try to do the above it fails to open to java application due to the class folders trying to be referenced from where the vb.net application is launched

The code in the .bat is

@echo off
@title JavaApplet12
set CLASSPATH=.;dist\*
java -client -Dnet.sf.odinms.wzpath=wz server.Start
pause

And I know I can hard set the classpath and wzpath but users of my application will not want to do this.

How can I launch it in vb.net so that the application is launched from that location and can read the files from that folder location.

This should be resolvable by setting the working directory of the process before you start it:

Dim processStartInfo = New ProcessStartInfo()
processStartInfo.WorkingDirectory = Path.GetDirectoryName(O.FileName)
processStartInfo.FileName = "BasicStart.bat"
Process.Start(processStartInfo)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM