Sign in to follow this  
PureSnowX

[C#] Starting a process can't find the .exe file

Recommended Posts

Hello forums!
Today I'v been trying to upgrade my custom "Minecraft.exe" launcher to force Java to allocate more RAM!
Basicly I'v been trying to achive this:
Minecraft.bat
[code]

@echo off

set minMemoryAllocated=1024
set maxMemoryAllocated=1024

echo #==========================================#
echo # M I N E C R A F T A L L O C A T O R
echo # created by: Victor Karlsson
echo #==========================================#
echo #=== PARAMETERS ===========================#
echo Starting Minecraft with:
echo Minimum RAM allocated: %minMemoryAllocated%
echo Maximum RAM allocated: %maxMemoryAllocated%

javaw -Xmx%minMemoryAllocated%m -Xms%maxMemoryAllocated%m -jar "F:\SomeDirectoryHere\Minecraft.exe"
[/code]

Into C# .exe file!
But I'm running into problems when I'm trying to get this line to work:
[code]
javaw -Xmx%minMemoryAllocated%m -Xms%maxMemoryAllocated%m -jar "F:\SomeDirectoryHere\Minecraft.exe"
[/code]
Oh and I'm also using:
[code]
processInformation.EnvironmentVariables["appdata"] = currentDirectory;
[/code]
To allow Minecraft to be played from my USB and such without the use of APPDATA folder.

Anyways this here is my C# code so far!:
[code]

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Diagnostics;

namespace Minecrafter
{
class Program
{
public static readonly string currentDirectory = Directory.GetCurrentDirectory();

public static readonly string minAllocatedRAM = "1024";
public static readonly string maxAllocatedRAM = "1024";
public static readonly string pathCommand = "javaw -Xmx1024m -Xms1024m -jar \"" + currentDirectory + @"\" + "Minecraft.exe\"";

/*Just for testing!*/
public static readonly string c = "\"" + currentDirectory + @"\Minecraft.exe" + "\"";
public static readonly string b = @"javaw -Xmx1024 -Xms1024 -jar " + c;

static void Main(string[] args)
{
Console.ReadKey(false);
Console.WriteLine("#==========================================#");
Console.WriteLine("# M I N E C R A F T A L L O C A T O R");
Console.WriteLine("# Created by: Victor Karlsson");
Console.WriteLine("#==========================================#");
if (!File.Exists(currentDirectory + @"\Minecraft.exe"))
{
Console.WriteLine("ERROR: Please make sure Minecraft.exe is placed in the same directory as Minecrafter.exe");
Console.ReadKey(false);
}
else
{
try
{
ProcessStartInfo processInformation = new ProcessStartInfo(b);
processInformation.UseShellExecute = false;
processInformation.EnvironmentVariables["appdata"] = currentDirectory;

Process.Start(processInformation);

Console.WriteLine("\n#=========PARAMETERS===================#");
Console.WriteLine("Minimum RAM Allocated: {0}", minAllocatedRAM);
Console.WriteLine("Maximum RAM Allocated: {0}", maxAllocatedRAM);
Console.ReadKey(false);
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
Console.ReadKey(false);
}
}

Environment.Exit(0);
}
}
}
[/code]


EDIT:
The problem is that the C# program can't find the .exe to run with the javaw parameters
So after trying I decided to ask you guys! :D

Share this post


Link to post
Share on other sites
Yes the path was correct:
Minecraft.exe and My application is both in "D:\Minecraft\"
The program started Minecraft when I did:

[code]ProcessStartInfo processInformation = new ProcessStartInfo(currentDirectory+@"\Minecraft.exe")[/code]

Looks like the javaw -Xmx1024 -Xms1024m -jar line is the problem! How can I make the process run with these parameters?

Share this post


Link to post
Share on other sites
Solved this! Finally! Such a stupid mistake really...
I was trying to run Minecraft.exe with the "javaw -Xmxm -Xmsm -jar" parameters but then I realized that "javaw" is the process I want to start and feed it the arguments for starting an java application.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this