Obtain the detailed description of the current Windows operating system version.

Source: Internet
Author: User
Obtain the detailed description of the current Windows operating system version.
Currently, Windows 2003 is supported.

Cstring getosdesc (void)
{
Cstring sosinfo, stmp;
Osversioninfoex osvi;
Bool bosversioninfoex;

Sosinfo = "N/";

// Try calling getversionex using the osversioninfoex structure.
// If that fails, try using the osversioninfo structure.
Zeromemory (& osvi, sizeof (osversioninfoex ));
Osvi. dwosversioninfosize = sizeof (osversioninfoex );

If (! (Bosversioninfoex = getversionex (osversioninfo *) & osvi )))
{
Osvi. dwosversioninfosize = sizeof (osversioninfo );
If (! Getversionex (osversioninfo *) & osvi ))
Return sosinfo;
}

Switch (osvi. dwplatformid)
{
// Test for the Windows NT product family.
Case ver_platform_win32_nt:
// Test for the specific product family.
If (osvi. dwmajorversion = 5 & osvi. dwminorversion = 2)
Sosinfo = "Microsoft Windows Server 2003 Family ";

If (osvi. dwmajorversion = 5 & osvi. dwminorversion = 1)
Sosinfo = "Microsoft Windows XP ";

If (osvi. dwmajorversion = 5 & osvi. dwminorversion = 0)
Sosinfo = "Microsoft Windows 2000 ";

If (osvi. dwmajorversion <= 4)
Sosinfo = "Microsoft Windows NT ";

// Test for specific product on Windows NT 4.0 SP6 and later.
If (bosversioninfoex)
{
// Test for the workstation type.
If (osvi. wproducttype = ver_nt_workstation)
{
If (osvi. dwmajorversion = 4)
Sosinfo + = "Workstation 4.0 ";
Else if (osvi. wsuitemask & ver_suite_personal)
Sosinfo + = "Home Edition ";
Else
Sosinfo + = "professional ";
}
// Test for the server type.
Else if (osvi. wproducttype = ver_nt_server)
{
If (osvi. dwmajorversion = 5 & osvi. dwminorversion = 2)
{
If (osvi. wsuitemask & ver_suite_datacenter)
Sosinfo + = "datacenter edition ";
Else if (osvi. wsuitemask & ver_suite_enterprise)
Sosinfo + = "Enterprise Edition ";
Else if (osvi. wsuitemask = ver_suite_blade)
Sosinfo + = "web edition ";
Else
Sosinfo + = "Standard Edition ";
}
Else if (osvi. dwmajorversion = 5 & osvi. dwminorversion = 0)
{
If (osvi. wsuitemask & ver_suite_datacenter)
Sosinfo + = "datacenter server ";
Else if (osvi. wsuitemask & ver_suite_enterprise)
Sosinfo + = "Advanced Server ";
Else
Sosinfo + = "server ";
}
Else // Windows NT 4.0
{
If (osvi. wsuitemask & ver_suite_enterprise)
Sosinfo + = "Server 4.0, Enterprise Edition ";
Else
Sosinfo + = "Server 4.0 ";
}
}
}
Else // test for specific product on Windows NT 4.0 SP5 and earlier
{
Hkey;
Char szproducttype [80];
DWORD dwbuflen = 80;
Long LRET;

Stmp = "system // CurrentControlSet // control // productoptions ";
LRET = regopenkeyex (HKEY_LOCAL_MACHINE, stmp,
0, key_query_value, & hkey );
If (LRET! = Error_success)
Return sosinfo;

Stmp = "producttype ";
LRET = regqueryvalueex (hkey, stmp, null, null, (lpbyte) szproducttype, & dwbuflen );
If (LRET! = Error_success) | (dwbuflen> 80 ))
Return sosinfo;

Regclosekey (hkey );

Stmp = "winnt ";
Sosinfo + = "workstation ";
Stmp = "lanmannt ";
If (stmp = szproducttype)
Sosinfo + = "server ";
Stmp = "servernt ";
If (stmp = szproducttype)
Sosinfo + = "Advanced Server ";

Stmp. Format (L "% d. % d", osvi. dwmajorversion, osvi. dwminorversion );
Sosinfo + = stmp;
}

// Display Service Pack (if any) and build number.
Stmp = "Service Pack 6 ";
If (osvi. dwmajorversion = 4 & (stmp = osvi. szcsdversion ))
{
Hkey;
Long LRET;

// Test for SP6 versus SP6a.
Stmp = "software // Microsoft // Windows NT // CurrentVersion // hotfix // q246009 ";
LRET = regopenkeyex (HKEY_LOCAL_MACHINE, stmp,
0, key_query_value, & hkey );
If (LRET = error_success)
{
Stmp. Format (L "Service Pack 6a (build % d)/n", osvi. dwbuildnumber & 0 xFFFF );
Sosinfo + = stmp;
}
Else // Windows NT 4.0 prior to SP6a
{
Stmp. Format (L "% s (build % d)/n", osvi. szcsdversion, osvi. dwbuildnumber & 0 xFFFF );
Sosinfo + = stmp;
}

Regclosekey (hkey );
}
Else // Windows NT 3.51 and earlier or Windows 2000 and later
{
Stmp. Format (L "% s (build % d)/n", osvi. szcsdversion, osvi. dwbuildnumber & 0 xFFFF );
Sosinfo + = stmp;
}
Break;

// Test for the Windows 95 product family.
Case ver_platform_win32_windows:
If (osvi. dwmajorversion = 4 & osvi. dwminorversion = 0)
{
Sosinfo = "Microsoft Windows 95 ";
If (osvi. szcsdversion [1] = 'C' | osvi. szcsdversion [1] = 'B ')
Sosinfo + = "osr2 ";
}

If (osvi. dwmajorversion = 4 & osvi. dwminorversion = 10)
{
Sosinfo = "Microsoft Windows 98 ";
If (osvi. szcsdversion [1] = 'A ')
Sosinfo + = "se ";
}

If (osvi. dwmajorversion = 4 & osvi. dwminorversion = 90)
{
Sosinfo = "Microsoft Windows Millennium Edition ";
}
Break;

Case ver_platform_win32s:
Sosinfo = "Microsoft win32s ";
Break;
}

Return sosinfo;
}

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.