您可以通过注册表进行操作。但是,您在错误的位置寻找。我为您提供了一个简单的例子:
private string GetJavaInstallationPath(){ string environmentPath = Environment.GetEnvironmentVariable("JAVA_HOME"); if (!string.IsNullOrEmpty(environmentPath)) { return environmentPath; } string javaKey = "SOFTWARE\JavaSoft\Java Runtime Environment\"; using (Microsoft.Win32.RegistryKey rk = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(javaKey)) { string currentVersion = rk.GetValue("CurrentVersion").ToString(); using (Microsoft.Win32.RegistryKey key = rk.OpenSubKey(currentVersion)) { return key.GetValue("JavaHome").ToString(); } }}然后使用它,只需执行以下操作:
string installPath = GetJavaInstallationPath();string filePath = System.IO.Path.Combine(installPath, "bin\Java.exe");if (System.IO.File.Exists(filePath)){ // We have a winner}


