Get the version of the current operating system

xiaoxiao2021-03-06  56

#include #include

#define buffsize 80

Int main () {osversioninfoEx Osvi; Bool BosversionInfoEx;

// Try Calling getversionEx Using The OsversionInfoEx Structure. //Iff That Fails, Try Using The OsversionInfo Structure.

ZeromeMory (osversioninfoex); Osvi.dwosveionsInfosize = Sizeof (OsversionInfoEx);

If (! (bosversioninfoEx = getversionex (osversioninfo *) & osvi))) {osvi.dwosversioninfosize = sizeof (osversioninfo); if (! getversionEx (osversioninfo *) & osvi) Return False;

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) Printf ("Microsoft Windows Server 2003 Family,");

IF (Osvi.dwmajorversion == 5 && Osvi.dwminorversion == 1) Printf ("Microsoft Windows XP");

IF (Osvi.dwmajorversion == 5 && Osvi.dwminorversion == 0) Printf ("Microsoft Windows 2000");

IF (Osvi.dwmajorversion <= 4) Printf ("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) printf ( "Workstation 4.0 "); Else if (Osvi.Wsuitemask & Ver_suite_Personal) PRINTF (" HOME Edition "); Else Printf (" Professional ");} // Test for the Server Type. Else IF (Osvi.wProductType == Ver_NT_SERVER || OSVI .wProductType == VER_NT_DOMAIN_CONTROLLER) {if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2) {if (osvi.wSuiteMask & VER_SUITE_DATACENTER) printf ( "Datacenter Edition"); else if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE) printf ("Enterpri SE Edition "); Else if (Osvi.WsuItemsk == Ver_suite_blade) Printf (" Web Edition "); Else Printf (" Standard Edition ");}

else if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0) {if (osvi.wSuiteMask & VER_SUITE_DATACENTER) printf ( "Datacenter Server"); else if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE) printf ( "Advanced Server") Else Printf ("Server");} else // windows NT 4.0 {if (Osvi.WsuItemsk & Ver_suite_Enterprise) Printf ("Server 4.0, Enterprise Edition"); Else Printf ("Server 4.0");}}} else / / TEST for Specific Product On Windows NT 4.0 SP5 and Earlier {HKEY HKEY; Char SzproductType [BufSize]; DWORD DWBUFLEN = BUFSIZE; Long Lret;

Lret = regopenkeyex (HKEY_LOCAL_MACHINE, "System // CurrentControlSet // Control // ProductOptions", 0, Key_Query_Value, & HKEY); if (LRET! = Error_Success) Return False;

Lret = RegQueryValueex (HKEY, "ProductType", NULL, NULL, (LPBYTE) SZPRODUCTTYPE, & DWBUFLEN; IF (LRET! = Error_Success) || (dwbufflen> buffsize) Return False;

RegcloseKey (HKEY);

IF (LSTRCMPI ("Winnt", SzProductType == 0) Printf ("Workstation"); if (LSTRCMPI ("LSTRCMPI (" LanmanNT ", SzProductType == 0) Printf (" Server "); if (lstrcmpi (" Servernt ", SzProductType) == 0) Printf ("Advanced Server"); Printf ("% D.% D", OSVI.DWMAJORVERSION, OSVI.DWMINORVERSION;}

// Display service pack (if any) and build number.

IF (Osvi.dwmajorversion == 4 &&lstrcmpi (Osvi.Szcsdversion, "Service Pack 6") == 0) {HKEY HKEY; Long Lret;

. // Test for SP6 versus SP6a lRet = RegOpenKeyEx (HKEY_LOCAL_MACHINE, "SOFTWARE // Microsoft // Windows NT // CurrentVersion // Hotfix // Q246009", 0, KEY_QUERY_VALUE, & hKey); if (lRet == ERROR_SUCCESS) printf ( "Service Pack 6A (Build% D) / N", OSVI.DWBUILDNUMBER & 0xFFFF); ELSE // Windows NT 4.0 Prior To SP6A {Printf ("% s (Build% D) / N", OSVI.SZCSDVERSION, OSVI. DWBUILDNUMBER & 0xFFFF);

RegcloseKey (HKEY);} else // windows nt 3.51 and years {printf ("% s (build% d) / n", osvi.szcsdversion, osvi.dwbuildnumber & 0xfff);

Break;

// Test for the Windows 95 Product Family. Case Ver_Platform_WIN32_WINDOWS:

IF (Osvi.dwmajorversion == 4 && Osvi.dwminorversion == 0) {Printf ("Microsoft Windows 95"); if (Osvi.Szcsdversion [1] == 'c' || Osvi.szcsdversion [1] == ' B ') Printf ("OSR2");} if (Osvi.dwmajorversion == 4 && Osvi.dwminorversion == 10) {PrintF ("Microsoft Windows 98"); if (Osvi.Szcsdversion [1] ==' A ' ) PRINTF ("se");

IF (Osvi.dwmajorversion == 4 && Osvi.dwminorversion == 90) {Printf ("Microsoft Windows Millennium Edition / N");} Break;

Case Ver_Platform_Win32S:

Printf ("Microsoft Win32S / N"); Break;} Return True;

转载请注明原文地址:https://www.9cbs.com/read-118282.html

New Post(0)