• Advertisement
Sign in to follow this  

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

This topic is 2333 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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


@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"


Into C# .exe file!
But I'm running into problems when I'm trying to get this line to work:

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

Oh and I'm also using:

processInformation.EnvironmentVariables["appdata"] = currentDirectory;

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!:


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);
}
}
}



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
Advertisement
Yes the path was correct:
Minecraft.exe and My application is both in "D:\Minecraft\"
The program started Minecraft when I did:

ProcessStartInfo processInformation = new ProcessStartInfo(currentDirectory+@"\Minecraft.exe")

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
Sign in to follow this  

  • Advertisement