Code Paintdotnet. systemlayer. OS class from paint. net
This code checks the entries in the registry to determine whether. NET 2.0/3.0 is installed. Since paint. Net was developed by Microsoft employees, it can be considered as a more accurate method.
Private Static Bool Isdotnet2versioninstalled ( Int Major, Int Minor, Int Build)
{
Const String Regkeynameformat = " SOFTWARE \ Microsoft \ Net Framework Setup \ NDP \ v {0}. {1}. {2} " ;
Const String Regvaluename = " Install " ;
String Regkeyname = String . Format (regkeynameformat, Major. tostring (cultureinfo. invariantculture ),
Minor. tostring (cultureinfo. invariantculture), build. tostring (cultureinfo. invariantculture ));
Return Checkforregvalueequals1 (regvaluename, regkeyname );
}
Private Static Bool Isdotnet3versioninstalled ( Int Major, Int Minor, Int Build)
{
Bool Result = False ;
Const String Regvaluename = " Installsuccess " ;
If ( ! Result)
{
Const String Regkeynameformat = " SOFTWARE \ Microsoft \ Net Framework Setup \ NDP \ v {0}. {1} \ setup " ;
String Regkeyname = String . Format (regkeynameformat, Major, minor );
Result | = Checkforregvalueequals1 (regkeyname, regvaluename );
}
If ( ! Result)
{
// There seems to be a bug in x64. Net 3.0 where it only records its success in the 32-bit Section of the Registry.
Const String Regkeynameformat2 = " Software \ wow6432node \ Microsoft \ Net Framework Setup \ NDP \ v {0}. {1} \ setup " ;
String Regkeyname2 = String . Format (regkeynameformat2, Major, minor );
Result | = Checkforregvalueequals1 (regkeyname2, regvaluename );
}
Return Result;
}
Private Static Bool Checkforregvalueequals1 ( String Regkeyname, String Regvaluename)
{
Using (Registrykey key = Registry. localmachine. opensubkey (regkeyname, False ))
{
Object Value = Null ;
If (Key ! = Null )
{
Value=Key. getvalue (regvaluename );
}
Return (Value ! = Null && Value Is Int && ( Int ) Value = 1 );
}
}