1

I have a VB App that is calling .bat files externally, I figured out how to add the bat files to the project, but how do I reference their location in code vs externally referenced outside of the solution folder

Ex

My.code.reference.location(somefile.bat)
not >>> Process.Start("C:\Users\person\file.bat")

my actual work

Try

Dim startInfo As New ProcessStartInfo("cmd")

startInfo.WindowStyle = ProcessWindowStyle.Hidden

startInfo.Arguments = "/C C:\Users\luna\install.bat"

startInfo.RedirectStandardOutput = True

startInfo.UseShellExecute = False

startInfo.CreateNoWindow = True

Dim p = Process.Start(startInfo)

Dim result = p.StandardOutput.ReadToEnd()

p.Close()

MsgBox("Service Installed")

Catch ex As Exception

MsgBox("Error")

End Try

my question is, the line where it points to a path and a batch file, how do i include the batch file in the project and script it where its referenced internally vs the path its pointing to now

1 Answer 1

1

This might help, Its worth trying;

  • Right-click your project in Solution Explorer → Add → Existing Item.
  • Select your .bat file.
  • Set its Build Action to Content and Copy to Output Directory to Copy Always.

Reference the File in the Code:

Use a relative path to the .bat file in your project directory:

Dim batFilePath As String = Path.Combine(Application.StartupPath, "install.bat")
Dim startInfo As New ProcessStartInfo("cmd") With {
    .WindowStyle = ProcessWindowStyle.Hidden,
    .Arguments = "/C " & batFilePath,
    .RedirectStandardOutput = True,
    .UseShellExecute = False,
    .CreateNoWindow = True
}
Dim p = Process.Start(startInfo)
Dim result = p.StandardOutput.ReadToEnd()
p.Close()
MsgBox("Service Installed")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.