How to check whether. NET 2.0 and. Net 3.0 [ZT] are installed?

Source: Internet
Author: User
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 );
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.