0

Alright guys I have a copy of minecraft wich is a java program launched by Minecraft.exe.

Inside the same folder is my program (lets call it launcher.exe) wich I am programming in VB.net and a Folder called LocalAppData.

If I place a shortcut in the same folder as Minecraft.exe, clear the "start in" field and put this in the target field:

C:\Windows\System32\cmd.exe /c start cd LocalAppData&& set APPDATA=%cd%\LocalAppData&& javaw -Xms4096M -Xmx4096M -cp LocalAppData\Minecraft.exe net.minecraft.LauncherFrame

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

My Question is: 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?

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.

I thought I would be able to use the same code inside a Shell() command to produce the same effect, but it appears not.

Ideally I want to create a program that runs minecraft with:

  • Custom memory allocation
  • Local filepaths so that it can be run portably
  • The appdata folder changed to the subfolder so that it can be run portably
  • Those command windows either gone or minimised and then close automatically when minecraft is closed by the user.

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.

Note: 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.

Thank you for reading all this and sorry for the long post.

Edit

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"

'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 " & appPath & "&& set APPDATA=" & appPath & "\LocalAppData"
appDataStartInfo.UseShellExecute = True
Process.Start(appDataStartInfo)
'Launch Minecraft
javaStartInfo.FileName = "javaw.exe"
javaStartInfo.Arguments = "-Xms4096M -Xmx4096M -cp " & appPath & "\LocalAppData\.minecraft\bin\Minecraft.jar net.minecraft.LauncherFrame"
javaStartInfo.UseShellExecute = True
Process.Start(javaStartInfo)

Does anyone see where I've gone wrong?

1 Answers1

1

The Process class (http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx )allows you to launch a process. You set it up with a ProcessStartInfo instance (http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo(v=vs.80).aspx ).

I don't have the time to give you all the details, but this pseudo-code should get you started :

Dim startInfo As ProcessStartInfo = new ProcessStartInfo()
startInfo.FileName = "javaw.exe" 'That's the name of your executable
startInfo.Arguments = "your argument line" 
startInfo.UseShellExecute = true 'Needed to open a command window   
Process.Start(startInfo)
Ksempac
  • 1,842
  • 2
  • 18
  • 23
  • Ok, this is what I have so far: – Lloyd Pinchen Jul 25 '12 at 01:49
  • Doh, sorry - post was too long. Code so far is in the description of the question now. – Lloyd Pinchen Jul 25 '12 at 02:05
  • You're launching 2 processes, one to set up some environment variables and the other to launch java. Are you sure your modifications are persistant? I wouldn't be surprised if they are local to your first process. If that's the problem, one way to solve it would be to uses vb.Net to generate a batch (dos) file that does both, and launch the batch with vb.net – Ksempac Jul 25 '12 at 06:10