00001
00002 #define DKUTIL_C_OS_C
00003 #include "dkcOS.h"
00004
00005 #ifdef WIN32
00006
00007 int WINAPI dkcGetOSVersion(){
00008 int r = -1;
00009 OSVERSIONINFO os;
00010 os.dwOSVersionInfoSize=sizeof(os);
00011
00012
00013 if(GetVersionEx(&os)==0)
00014 goto End;
00015
00016 if(os.dwMajorVersion<=3){
00017
00018
00019 if(os.dwMinorVersion==51){
00020 r = enuWindowsNT3_51;
00021 goto End;
00022 }
00023 if(os.dwPlatformId==VER_PLATFORM_WIN32s){
00024 r = enuWindows3_1;
00025 goto End;
00026 }
00027 }
00028
00029 switch(os.dwPlatformId){
00030 case VER_PLATFORM_WIN32s:
00031 r = enuWindows3_1;
00032 break;
00033
00034 case VER_PLATFORM_WIN32_WINDOWS:
00035 if(os.dwMajorVersion >=4)
00036 {
00037 if(os.dwMinorVersion<10){
00038 r = enuWindows95;
00039 goto End;
00040 }
00041 if(os.dwMinorVersion<90){
00042 r = enuWindows98;
00043 goto End;
00044 }
00045
00046 if(os.dwMinorVersion>=90){
00047 r = enuWindowsMe;
00048 goto End;
00049 }else{
00050 r = -2;
00051 goto End;
00052 }
00053 }
00054 if(os.dwMajorVersion==5){
00055
00056 if(os.dwMinorVersion==0){
00057 r = enuWindows2000;
00058 goto End;
00059 }
00060 if(os.dwMinorVersion>0){
00061 r = enuWindowsXP;
00062 goto End;
00063 }else{
00064 r = -2;
00065 goto End;
00066 }
00067 }
00068 break;
00069
00070
00071 case VER_PLATFORM_WIN32_NT:
00072 if(os.dwMajorVersion==4)
00073 r = enuWindowsNT4_0;
00074
00075 if(os.dwMajorVersion==5){
00076 if(os.dwMinorVersion==0)
00077 r = enuWindows2000;
00078 if(os.dwMinorVersion>0){
00079 r = enuWindowsXP;
00080 }
00081 else{
00082 return -2;
00083 }
00084 }
00085 return -2;
00086 break;
00087 default:
00088 return -2;
00089 break;
00090 }
00091 End:
00092 return r;
00093 }
00094
00095
00096
00097
00098
00099
00100 #if (_MSC_VER > 1200)
00101
00102 int WINAPI dkcGetOSVersionEx(int *Extension)
00103 {
00104 int result=-1;
00105 int ext=0;
00106 OSVERSIONINFOEX osvi={0};
00107 BOOL SucceededFlag=FALSE;
00108
00109
00110 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
00111
00112 SucceededFlag = GetVersionEx((OSVERSIONINFO *)&osvi);
00113 if (!SucceededFlag) {
00114 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
00115 if(!GetVersionEx((OSVERSIONINFO *)&osvi)){
00116 return -1;
00117 }
00118 }
00119
00120 switch (osvi.dwPlatformId)
00121 {
00122 case VER_PLATFORM_WIN32_NT:
00123 if (osvi.dwMajorVersion <= 4) {
00124 result = enuWindowsNT4_0;
00125 }
00126
00127 if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0) {
00128 result = enuWindows2000;
00129 }
00130 if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1){
00131 result = enuWindowsXP;
00132 }
00133 if (SucceededFlag) {
00134 if (osvi.wProductType == VER_NT_WORKSTATION) {
00135
00136 if (osvi.wSuiteMask & VER_SUITE_PERSONAL) {
00137 ext = edkOSE_HomeEdition;
00138 }else {
00139 ext = edkOSE_Professional;
00140 }
00141 }else if (osvi.wProductType == VER_NT_SERVER) {
00142 if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1) {
00143 result = enuWindows_NET;
00144 }
00145
00146 if (osvi.wSuiteMask & VER_SUITE_DATACENTER) {
00147 ext = edkOSE_DataCenter_Server;
00148 }else if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE) {
00149 if( osvi.dwMajorVersion == 4 ) {
00150 ext = edkOSE_Advanced_Server;
00151 }
00152 else {
00153 ext = edkOSE_Enterprise_Server;
00154 }
00155 }
00156 else if (osvi.wSuiteMask == VER_SUITE_BLADE) {
00157 ext = edkOSE_Web_Server;
00158 }
00159 else {
00160 ext = edkOSE_Server;
00161 }
00162 }
00163 }
00164 else {
00165 HKEY hKey;
00166 char szProductType[80];
00167 DWORD dwBufLen;
00168
00169 RegOpenKeyEx(HKEY_LOCAL_MACHINE,
00170 "SYSTEM\\CurrentControlSet\\Control\\ProductOptions",
00171 0, KEY_QUERY_VALUE, &hKey );
00172 RegQueryValueEx(hKey, "ProductType", NULL, NULL,
00173 (LPBYTE)szProductType, &dwBufLen);
00174 RegCloseKey(hKey);
00175
00176 if (lstrcmpi("WINNT", szProductType) == 0) {
00177 ext= edkOSE_Professional;
00178 }
00179 if (lstrcmpi("LANMANNT", szProductType) == 0) {
00180 ext = edkOSE_Server;
00181 }
00182 if (lstrcmpi( "SERVERNT", szProductType) == 0) {
00183 ext = edkOSE_Advanced_Server;
00184 }
00185 }
00186
00187 break;
00188
00189 case VER_PLATFORM_WIN32_WINDOWS:
00190 if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0) {
00191 result = enuWindows95;
00192 if (osvi.szCSDVersion[1] == 'C' || osvi.szCSDVersion[1] == 'B') {
00193 ext = edkOSE_OSR2;
00194 }
00195 }
00196
00197 if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10) {
00198 result = enuWindows98;
00199 if (osvi.szCSDVersion[1] == 'A') {
00200 ext = enuOSE_SE;
00201 }
00202 }
00203
00204 if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90) {
00205 result = enuWindowsME;
00206 }
00207
00208 break;
00209 default:
00210 return -1;
00211 }
00212
00213 if(Extension){
00214 *Extension = ext;
00215 }
00216
00217 return result;
00218 }
00219
00220
00221 #endif
00222
00223
00224 #endif