none
Having a .BAT file to open up another .EXE JAR file - C# - HELP!

    Question

  • Hello, I'm currently working on a software for a game-servers(shortcut software) for a minecraft server.

     

    I got the server software, when I run it a window will not appear(a.k.a Server Interface) So, I found this INTERFACE you can use to your server software.

     

    It works PERFECTLY by clicking on a .BAT file to launch the server(by manual)

     

    So, I was thinking how to actually make a code for that? If I try to bind "C:\Users\Armin\Desktop\Bukkit\crafty.bat" this is the Launcher.bat file for the server interface.

    If I bind that code to a button, it doesnt work.... It just comes up as an "ERROR COULD NOT FIND FILE"

    but it works if I manually find the file and double click on it....

     

    Any suggestions?

     

    Hope you understand!

     

    Regards,

    Armin Pasalic.




    • Edited by thunderZ0N3 Monday, May 30, 2011 8:45 PM So the Title makes more sense against my problem!!!!
    Saturday, May 28, 2011 3:18 PM

All replies

  • Bump....
    Saturday, May 28, 2011 5:41 PM
  • Bump Bump.
    Monday, May 30, 2011 10:47 AM
  • Place sample code calling the .bat file
    Monday, May 30, 2011 10:56 AM
  • How are you trying to "bind that code to a button"?

    Try this:

    System.Diagnostics.Process p = new System.Diagnostics.Process();
    p.StartInfo = new System.Diagnostics.ProcessStartInfo(@"C:\Users\Armin\Desktop\Bukkit\crafty.bat");
    p.Start();
    


    Please mark this as answer or vote as helpful if it solved your problem
    Monday, May 30, 2011 12:11 PM
  • That didnt help.. :-(((

     

    What I mean by that is like having a shortcut for the user to launch the server, one-click server is running.

     

    Same error:

     

    WINDOWS CANNOT FIND JAVAW

     

    If I manually click the crafty.bat file it works.

    Monday, May 30, 2011 3:27 PM
  • Hello,

     

    maybe in your .bat file are incorrect pathes to java services.

    Try put absolute pathes in your .bat file.

     

    Regards

    Adam


    Monday, May 30, 2011 3:33 PM
  • Does the .bat file have other files in the same folder?

    try this instead:

     

    System.Diagnostics.Process p = new System.Diagnostics.Process();
    p.StartInfo = new System.Diagnostics.ProcessStartInfo(@"C:\Users\Armin\Desktop\Bukkit\crafty.bat");
    p.StartInfo.WorkingDirectory = @"C:\Users\Armin\Desktop\Bukkit";
    p.Start();
    

     


    Please mark this as answer or vote as helpful if it solved your problem
    Monday, May 30, 2011 5:29 PM
  • @Adam Bielasty

     

    Destination of bat file: C:\Users\Armin\Desktop\Bukkit\crafty.bat

    Code in bat file: 

    @echo off

    start /b javaw -Xincgc -Xmx1G -jar crafty.jar

     

    This will launch(by manually clicking on it) C:\Users\Armin\Desktop\Bukkit\crafty.jar              (This is the interface created in a java)

     

     

    @GregHenry

    WINDOWS CANNOT FIND JAVAW.

     

    :-(

    Again, same error. :-( 

     

     

    Monday, May 30, 2011 6:11 PM
  • Try editing the batch file and replace javaw with the full path

    the default path of the javaw.exe is C:\Program Files (x86)\Java\jre6\bin for windows 7. It looks like you're running under win 7 too.

    edit the batch file to

    @echo off

    start /b C:\Program Files (x86)\Java\jre6\bin\javaw.exe -Xincgc -Xmx1G -jar crafty.jar

    You can check if the path containing the javaw file is taken in the Process by debugging and checking the value of the Path variable

     String Path = p.StartInfo.EnvironmentVariables["path"];
    


    Please mark this as answer or vote as helpful if it solved your problem
    Monday, May 30, 2011 6:39 PM
  • That didnt even work.. :/
    Monday, May 30, 2011 7:54 PM
  • Hello thunderZ0N3,

    hmm... I don't know what can be wrong.

    I have a idea. If you have Win7 you can click the right button of mouse on this .bat file and chose "run as administrator".

    Regards

    Adam

    Monday, May 30, 2011 8:07 PM
  • Yeah, but what if I in-need of sharing it to the public? :/
    Monday, May 30, 2011 8:18 PM
  • I could also use a CMD GUI.

     

    The launcher for the .bat file is the following(I run JAVA 7)

     

    @ECHO OFF

     

    SET BINDIR=%~dp0

     

    CD /D "%BINDIR%"

     

    "%ProgramFiles%\Java\jre7\bin\java.exe" -Xincgc -Xmx1G -jar craftbukkit.jar

     

    PAUSE

     

     

     

    -----------------------------------------------------------

     

    Yet again, if I code "  System.Diagnostics.Process.Start(@"C:\Users\Armin\Desktop\Bukkit\Launcher.bat");  " 

     

    It would still show the error "WINDOWS CANNOT FIND THE SPECIFIED FILE OR DIRECTORY"

     

    If I manually click on the .bat file, it will launch without any problems and run the server for me! :-(

    Monday, May 30, 2011 8:30 PM
  • Can you try something like this and let us know the results? This works fine with SystemInfo.exe

    private void button1_Click(object sender, EventArgs e)
        {
          Process myProcess = new Process();
    
          try
          {
            myProcess.StartInfo.UseShellExecute = false;
            string path = Environment.GetEnvironmentVariable("PATH");
            // You can start any process, batch file.
            myProcess.StartInfo.FileName = "D:\\DataInfo.bat";
            myProcess.StartInfo.CreateNoWindow = true;
    //        myProcess.StartInfo.EnvironmentVariables.Add("MyPath", Environment.GetEnvironmentVariable("PATH"));
            myProcess.Start();
            // This code assumes the process you are starting will terminate itself. 
            // Given that is is started without a window so you cannot terminate it 
            // on the desktop, it must terminate itself or you can do it programmatically
            // from this application using the Kill method.
          }
          catch (Exception)
          {
            //Console.WriteLine(e.Message);
          }
    


    --Trevor H.
    Send files to Hotmail.com: "MS_TREVORH"
    Monday, June 13, 2011 3:50 PM
  • I know this is too late to contribute but just for the sake of others who might face a similar kind of issue, check out this link http://programmingfree.blogspot.in/2012/07/how-to-call-executable-jar-file-from.html. Also make sure to escape the slashes in the path you hardcode in your program. 
    Wednesday, July 04, 2012 6:56 PM