-
-
Save efturtle/80e0cc20a39c62b5e9ad3f670b630ecc to your computer and use it in GitHub Desktop.
Aplicación de consola en C# para iniciar un archivo jar, verifica si java esta instalado y cumple con la versión mínima requerida.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Text; | |
| using System.Diagnostics; | |
| using System.Windows.Forms; | |
| namespace Jar_Starter | |
| { | |
| class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| try | |
| { | |
| string jar_file = "app.jar"; | |
| double java_min = 1.6; | |
| string javaKey = "SOFTWARE\\JavaSoft\\Java Runtime Environment\\"; | |
| using (Microsoft.Win32.RegistryKey rk = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(javaKey)) | |
| { | |
| string currentVersion = rk.GetValue("CurrentVersion").ToString(); | |
| double version = double.Parse(currentVersion); | |
| if (version >= java_min) | |
| { | |
| using (Microsoft.Win32.RegistryKey key = rk.OpenSubKey(currentVersion)) | |
| { | |
| string filePath = System.IO.Path.Combine(key.GetValue("JavaHome").ToString(), "bin\\java.exe"); | |
| if (System.IO.File.Exists(filePath)) | |
| { | |
| ProcessStartInfo JavaArgs = new ProcessStartInfo(filePath, "-jar \"" + Application.StartupPath + jar_file + "\""); | |
| JavaArgs.UseShellExecute = false; | |
| JavaArgs.CreateNoWindow = true; | |
| JavaArgs.WorkingDirectory = Application.StartupPath; | |
| Process proc = new Process(); | |
| proc.StartInfo = JavaArgs; | |
| proc.Start(); | |
| } | |
| else | |
| { | |
| Console.WriteLine("No se ha encontrado Java JRE instalado en el equipo."); | |
| Console.WriteLine("Puede encontrar la ultima versión en https://www.java.com/es/download/"); | |
| Console.ReadKey(); | |
| } | |
| } | |
| } | |
| else | |
| { | |
| Console.WriteLine("Java JRE instalado en el equipo es incompatible."); | |
| Console.WriteLine(); | |
| Console.WriteLine("Versión instalada: " + currentVersion); | |
| Console.WriteLine("Versión requerida: " + java_min.ToString()); | |
| Console.WriteLine(); | |
| Console.WriteLine("Puede encontrar la ultima versión en https://www.java.com/es/download/"); | |
| Console.WriteLine(); | |
| Console.WriteLine("Presione cualquier tecla para finalizar la aplicacion..."); | |
| Console.ReadKey(); | |
| } | |
| } | |
| } | |
| catch | |
| { | |
| Console.WriteLine("No se ha encontrado Java JRE instalado en el equipo."); | |
| Console.WriteLine("Puede encontrar la ultima versión en https://www.java.com/es/download/"); | |
| Console.ReadKey(); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment