/** * Returns true if the .NET framework of the given version (or greater) is installed. */ public static boolean isInstalled(int major, int minor) { try { // see http://support.microsoft.com/?scid=kb;en-us;315291 for the basic algorithm // observation in my registry shows that the actual key name can be things like "v2.0 SP1" // or "v2.0.50727", so the regexp is written to accommodate this. RegistryKey key = RegistryKey.LOCAL_MACHINE.openReadonly("SOFTWARE\\Microsoft\\.NETFramework"); try { for( String keyName : key.getSubKeys() ) { if (matches(keyName, major, minor)) return true; } return false; } finally { key.dispose(); } } catch (JnaException e) { if(e.getErrorCode()==2) // thrown when openReadonly fails because the key doesn't exist. return false; throw e; } }
/** * Returns true if the .NET framework of the given version (or greater) is installed. */ public static boolean isInstalled(int major, int minor) { try { // see http://support.microsoft.com/?scid=kb;en-us;315291 for the basic algorithm // observation in my registry shows that the actual key name can be things like "v2.0 SP1" // or "v2.0.50727", so the regexp is written to accommodate this. RegistryKey key = RegistryKey.LOCAL_MACHINE.openReadonly("SOFTWARE\\Microsoft\\.NETFramework"); try { for( String keyName : key.getSubKeys() ) { if (matches(keyName, major, minor)) return true; } return false; } finally { key.dispose(); } } catch (JnaException e) { if(e.getErrorCode()==2) // thrown when openReadonly fails because the key doesn't exist. return false; throw e; } }
/** * Returns true if the .NET framework of the given version (or greater) is installed. */ public static boolean isInstalled(int major, int minor) { try { // see http://support.microsoft.com/?scid=kb;en-us;315291 for the basic algorithm // observation in my registry shows that the actual key name can be things like "v2.0 SP1" // or "v2.0.50727", so the regexp is written to accomodate this. RegistryKey key = RegistryKey.LOCAL_MACHINE.openReadonly("SOFTWARE\\Microsoft\\.NETFramework"); try { for( String keyName : key.getSubKeys() ) { if (matches(keyName, major, minor)) return true; } return false; } finally { key.dispose(); } } catch (JnaException e) { if(e.getErrorCode()==2) // thrown when openReadonly fails because the key doesn't exist. return false; throw e; } }
/** * Returns true if the .NET framework of the given version (or greater) is installed. */ public static boolean isInstalled(int major, int minor) { try { // see http://support.microsoft.com/?scid=kb;en-us;315291 for the basic algorithm // observation in my registry shows that the actual key name can be things like "v2.0 SP1" // or "v2.0.50727", so the regexp is written to accomodate this. RegistryKey key = RegistryKey.LOCAL_MACHINE.openReadonly("SOFTWARE\\Microsoft\\.NETFramework"); try { for( String keyName : key.getSubKeys() ) { if (matches(keyName, major, minor)) return true; } return false; } finally { key.dispose(); } } catch (JnaException e) { if(e.getErrorCode()==2) // thrown when openReadonly fails because the key doesn't exist. return false; throw e; } }