run a .bat from C# without showing the CMD window

Question:

I am creating an .exe to run a .jar, it works, the only problem is that it shows a popup window ( CMD ) for a few milliseconds, is there any way to make this not happen?

Here my code to execute the .bat :

using System;

namespace Launch
{
    class MainClass
    {
        public static void Main(string[] args)

        {
            System.Diagnostics.Process.Start("start.bat");
        }
    }
}

this is my .bat :

@echo off
cd "C:\Program Files (x86)\START"
"C:\Program Files (x86)\START\jre8\bin\javaw.exe" -jar -XX:+UseConcMarkSweepGC -Xmx1024M -Xms1024M START.jar

Another way I tried was to do everything from C# (but got the same result):

using System.Diagnostics;

namespace Launch
{
    class MainClass
    {
        public static void Main(string[] args)

        {           

            ProcessStartInfo psi = new ProcessStartInfo();
            psi.Arguments = "-jar -XX:+UseConcMarkSweepGC -Xmx1024M -Xms1024M START.jar";
            psi.CreateNoWindow = true;
            psi.WindowStyle = ProcessWindowStyle.Hidden;
            psi.FileName = "jre8\\bin\\javaw.exe";
            Process.Start(psi);


        }
    }
}

Answer:

You need to set the use of a shell ( UseShellExecute ) to false, here is your code along with the missing line:

 ProcessStartInfo psi = new ProcessStartInfo();
 psi.UseShellExecute = false;  
 psi.Arguments = "-jar -XX:+UseConcMarkSweepGC -Xmx1024M -Xms1024M START.jar";
 psi.CreateNoWindow = true;
 psi.WindowStyle = ProcessWindowStyle.Hidden;
 psi.FileName = "jre8\\bin\\javaw.exe";
 Process.Start(psi);
Scroll to Top