title: VB.net - Running a java application using Shell() and set its appdata folder. multiple commands?
body: <p>Alright guys I have a copy of minecraft wich is a java program launched by Minecraft.exe.</p>
  
  <p>Inside the same folder is my program (lets call it launcher.exe) wich I am programming in VB.net and a Folder called LocalAppData.</p>
  
  <p>If I place a shortcut in the same folder as Minecraft.exe, clear the "start in" field and put this in the target field:</p>
  
  <blockquote>
    <p>C:\Windows\System32\cmd.exe /c start cd LocalAppData&amp;&amp; set APPDATA=%cd%\LocalAppData&amp;&amp; javaw -Xms4096M -Xmx4096M -cp LocalAppData\Minecraft.exe net.minecraft.LauncherFrame</p>
  </blockquote>
  
  <p>then minecraft launches with my custom memory allocation from inside the LocalAppData folder. Two command windows appear as well. One closes when minecraft does, but the other does not and needs to be closed by the user</p>
  
  <p><strong>My Question is:</strong> How do I acheive the same result in VB.net instead of with a windows shortcut and is there a way to either stop the command windows appearing or setting them both to close automatically?</p>
  
  <p>My goal is to launch minecraft from a subfolder, so local filepaths would be far preferrable to global filepaths, but figuring out the location of the application at runtime and working from a subfolder would be ok as well.</p>
  
  <p>I thought I would be able to use the same code inside a Shell() command to produce the same effect, but it appears not.</p>
  
  <p>Ideally I want to create a program that runs minecraft with:</p>
  
  <ul>
  <li>Custom memory allocation</li>
  <li>Local filepaths so that it can be run portably</li>
  <li>The appdata folder changed to the subfolder so that it can be run portably</li>
  <li>Those command windows either gone or minimised and then close automatically when minecraft is closed by the user.</li>
  </ul>
  
  <p>I know this is a big ask, but I'm 6 months into a programming course and I'll admit that I'm not the best programmer out there.
  Once I know how to do this I can create the rest of the program that manages multiple installations in seperate subfolders and lets you choose wich one to launch, but I just need help with the actual launching of the java application itself.</p>
  
  <p><strong>Note:</strong>
  I should clarify that Minecraft.exe is not something that I have made and that I don't program java. I'm just looking for a solution in VB.Net.</p>
  
  <p>Thank you for reading all this and sorry for the long post.</p>
  
  <p><strong>Edit</strong></p>
  
  <p>Thank you for the help. This is what I have so far, but it produces an error "Error: Could not create the JavaVirtualMachine. Error: A fatal exception has occurred. Program will exit"</p>
  
  <pre><code>'Declare Processes
  Dim appDataStartInfo As ProcessStartInfo = New ProcessStartInfo()
  Dim javaStartInfo As ProcessStartInfo = New ProcessStartInfo()
  Dim appPath As String = Application.StartupPath()
  'Launch appdata relocation process
  appDataStartInfo.FileName = "cmd.exe"
  appDataStartInfo.Arguments = "/c start cd " &amp; appPath &amp; "&amp;&amp; set APPDATA=" &amp; appPath &amp; "\LocalAppData"
  appDataStartInfo.UseShellExecute = True
  Process.Start(appDataStartInfo)
  'Launch Minecraft
  javaStartInfo.FileName = "javaw.exe"
  javaStartInfo.Arguments = "-Xms4096M -Xmx4096M -cp " &amp; appPath &amp; "\LocalAppData\.minecraft\bin\Minecraft.jar net.minecraft.LauncherFrame"
  javaStartInfo.UseShellExecute = True
  Process.Start(javaStartInfo)
  </code></pre>
  
  <p>Does anyone see where I've gone wrong?</p>