How to determine whether. NET Framework is installed in the (VC) System

Source: Internet
Author: User
This article provides a function to determine whether the. NET Framework environment is installed in the system. The function name is isnetpresent (). The working principle is to use the regopenkeyex API function to open the following registry key values in the current system:

HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \. netframework \ Policy \ V1.0

If this registration item is found, use the regqueryvalueex API function to check whether the. NET Framework release version is:

3705

If both of the preceding conditions are met, the function returns true:

Bool isnetpresent ()
{
Bool bretval = false;
Tchar sznetregkey [] = text ("SOFTWARE \ Microsoft \. netframework \ Policy \ V1.0 ");

Tchar szvalue [max_path];
DWORD dwvalue = 0;
Hkey HKLM = NULL;
Long lreg = 0;
Long lszreg = 0;
DWORD dwkeysize = 0;

Lreg = regopenkeyex (HKEY_LOCAL_MACHINE,
Sznetregkey,
0,
Key_read,
& HKLM );

If (error_success = lreg)
{
Dwkeysize = sizeof (szvalue)/sizeof (tchar );
Lszreg = regqueryvalueex (HKLM, text ("3705"), null, null, (byte *) szvalue, & dwkeysize );

If (error_success = lszreg ))
{
Regclosekey (HKLM );
Return true;
}
Else
{
Regclosekey (HKLM );
Return false;
}
}
Else
{
Return false;
}

}

This article is an online excerpt. If you have any questions, you can discuss it together!

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.