Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenversion.c
Go to the documentation of this file.
00001 /* 00002 * COPYRIGHT: See COPYING in the top level directory 00003 * PROJECT: ReactOS system libraries 00004 * FILE: dll/win32/kernel32/misc/version.c 00005 * PURPOSE: Version functions 00006 * PROGRAMMER: Ariadne (ariadne@xs4all.nl) 00007 Ged Murphy (gedmurphy@reactos.org) 00008 */ 00009 00010 #include <k32.h> 00011 00012 #define NDEBUG 00013 #include <debug.h> 00014 00015 /* FUNCTIONS ******************************************************************/ 00016 00017 VOID 00018 NTAPI 00019 SetRosSpecificInfo(IN LPOSVERSIONINFOEXW VersionInformation) 00020 { 00021 CHAR Buffer[sizeof(KEY_VALUE_PARTIAL_INFORMATION) + sizeof(DWORD)]; 00022 PKEY_VALUE_PARTIAL_INFORMATION kvpInfo = (PVOID)Buffer; 00023 OBJECT_ATTRIBUTES ObjectAttributes; 00024 DWORD ReportAsWorkstation = 0; 00025 HANDLE hKey; 00026 DWORD dwSize; 00027 NTSTATUS Status; 00028 UNICODE_STRING KeyName = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\ReactOS\\Settings\\Version"); 00029 UNICODE_STRING ValName = RTL_CONSTANT_STRING(L"ReportAsWorkstation"); 00030 00031 InitializeObjectAttributes(&ObjectAttributes, 00032 &KeyName, 00033 OBJ_OPENIF | OBJ_CASE_INSENSITIVE, 00034 NULL, 00035 NULL); 00036 00037 /* Don't change anything if the key doesn't exist */ 00038 Status = NtOpenKey(&hKey, KEY_READ, &ObjectAttributes); 00039 if (NT_SUCCESS(Status)) 00040 { 00041 /* Get the value from the registry and make sure it's a 32-bit value */ 00042 Status = NtQueryValueKey(hKey, 00043 &ValName, 00044 KeyValuePartialInformation, 00045 kvpInfo, 00046 sizeof(Buffer), 00047 &dwSize); 00048 if ((NT_SUCCESS(Status)) && 00049 (kvpInfo->Type == REG_DWORD) && 00050 (kvpInfo->DataLength == sizeof(DWORD))) 00051 { 00052 /* Is the value set? */ 00053 ReportAsWorkstation = *(PULONG)kvpInfo->Data; 00054 if ((VersionInformation->wProductType == VER_NT_SERVER) && 00055 (ReportAsWorkstation)) 00056 { 00057 /* It is, modify the product type to report a workstation */ 00058 VersionInformation->wProductType = VER_NT_WORKSTATION; 00059 DPRINT1("We modified the reported OS from NtProductServer to NtProductWinNt\n"); 00060 } 00061 } 00062 00063 /* Close the handle */ 00064 NtClose(hKey); 00065 } 00066 } 00067 00068 /* 00069 * @implemented 00070 */ 00071 DWORD 00072 WINAPI 00073 GetVersion(VOID) 00074 { 00075 PPEB Peb = NtCurrentPeb(); 00076 DWORD Result; 00077 00078 Result = MAKELONG(MAKEWORD(Peb->OSMajorVersion, Peb->OSMinorVersion), 00079 (Peb->OSPlatformId ^ 2) << 14); 00080 Result |= LOWORD(Peb->OSBuildNumber) << 16; 00081 return Result; 00082 } 00083 00084 /* 00085 * @implemented 00086 */ 00087 BOOL 00088 WINAPI 00089 GetVersionExW(IN LPOSVERSIONINFOW lpVersionInformation) 00090 { 00091 NTSTATUS Status; 00092 LPOSVERSIONINFOEXW lpVersionInformationEx; 00093 00094 if ((lpVersionInformation->dwOSVersionInfoSize != sizeof(OSVERSIONINFOW)) && 00095 (lpVersionInformation->dwOSVersionInfoSize != sizeof(OSVERSIONINFOEXW))) 00096 { 00097 SetLastError(ERROR_INSUFFICIENT_BUFFER); 00098 return FALSE; 00099 } 00100 00101 Status = RtlGetVersion((PRTL_OSVERSIONINFOW)lpVersionInformation); 00102 if (Status == STATUS_SUCCESS) 00103 { 00104 if (lpVersionInformation->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXW)) 00105 { 00106 lpVersionInformationEx = (PVOID)lpVersionInformation; 00107 lpVersionInformationEx->wReserved = 0; 00108 00109 /* ReactOS specific changes */ 00110 SetRosSpecificInfo(lpVersionInformationEx); 00111 } 00112 00113 return TRUE; 00114 } 00115 00116 return FALSE; 00117 } 00118 00119 /* 00120 * @implemented 00121 */ 00122 BOOL 00123 WINAPI 00124 GetVersionExA(IN LPOSVERSIONINFOA lpVersionInformation) 00125 { 00126 OSVERSIONINFOEXW VersionInformation; 00127 LPOSVERSIONINFOEXA lpVersionInformationEx; 00128 UNICODE_STRING CsdVersionW; 00129 NTSTATUS Status; 00130 ANSI_STRING CsdVersionA; 00131 00132 if ((lpVersionInformation->dwOSVersionInfoSize != sizeof(OSVERSIONINFOA)) && 00133 (lpVersionInformation->dwOSVersionInfoSize != sizeof(OSVERSIONINFOEXA))) 00134 { 00135 SetLastError(ERROR_INSUFFICIENT_BUFFER); 00136 return FALSE; 00137 } 00138 00139 VersionInformation.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW); 00140 00141 if (!GetVersionExW((LPOSVERSIONINFOW)&VersionInformation)) return FALSE; 00142 00143 /* Copy back fields that match both supported structures */ 00144 lpVersionInformation->dwMajorVersion = VersionInformation.dwMajorVersion; 00145 lpVersionInformation->dwMinorVersion = VersionInformation.dwMinorVersion; 00146 lpVersionInformation->dwBuildNumber = VersionInformation.dwBuildNumber; 00147 lpVersionInformation->dwPlatformId = VersionInformation.dwPlatformId; 00148 00149 if (lpVersionInformation->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXA)) 00150 { 00151 lpVersionInformationEx = (PVOID)lpVersionInformation; 00152 lpVersionInformationEx->wServicePackMajor = VersionInformation.wServicePackMajor; 00153 lpVersionInformationEx->wServicePackMinor = VersionInformation.wServicePackMinor; 00154 lpVersionInformationEx->wSuiteMask = VersionInformation.wSuiteMask; 00155 lpVersionInformationEx->wProductType = VersionInformation.wProductType; 00156 lpVersionInformationEx->wReserved = VersionInformation.wReserved; 00157 } 00158 00159 /* Convert the CSD string */ 00160 RtlInitEmptyAnsiString(&CsdVersionA, 00161 lpVersionInformation->szCSDVersion, 00162 sizeof(lpVersionInformation->szCSDVersion)); 00163 RtlInitUnicodeString(&CsdVersionW, VersionInformation.szCSDVersion); 00164 Status = RtlUnicodeStringToAnsiString(&CsdVersionA, &CsdVersionW, FALSE); 00165 return (NT_SUCCESS(Status)); 00166 } 00167 00168 /* 00169 * @implemented 00170 */ 00171 BOOL 00172 WINAPI 00173 VerifyVersionInfoW(IN LPOSVERSIONINFOEXW lpVersionInformation, 00174 IN DWORD dwTypeMask, 00175 IN DWORDLONG dwlConditionMask) 00176 { 00177 NTSTATUS Status; 00178 00179 Status = RtlVerifyVersionInfo((PRTL_OSVERSIONINFOEXW)lpVersionInformation, 00180 dwTypeMask, 00181 dwlConditionMask); 00182 switch (Status) 00183 { 00184 case STATUS_INVALID_PARAMETER: 00185 SetLastError(ERROR_BAD_ARGUMENTS); 00186 return FALSE; 00187 00188 case STATUS_REVISION_MISMATCH: 00189 DPRINT1("ReactOS returning version mismatch. Investigate!\n"); 00190 SetLastError(ERROR_OLD_WIN_VERSION); 00191 return FALSE; 00192 00193 default: 00194 /* RtlVerifyVersionInfo shouldn't report any other failure code! */ 00195 ASSERT(NT_SUCCESS(Status)); 00196 return TRUE; 00197 } 00198 } 00199 00200 /* 00201 * @implemented 00202 */ 00203 BOOL 00204 WINAPI 00205 VerifyVersionInfoA(IN LPOSVERSIONINFOEXA lpVersionInformation, 00206 IN DWORD dwTypeMask, 00207 IN DWORDLONG dwlConditionMask) 00208 { 00209 OSVERSIONINFOEXW viex; 00210 00211 /* NOTE: szCSDVersion is ignored, we don't need to convert it to Unicode */ 00212 viex.dwOSVersionInfoSize = sizeof(viex); 00213 viex.dwMajorVersion = lpVersionInformation->dwMajorVersion; 00214 viex.dwMinorVersion = lpVersionInformation->dwMinorVersion; 00215 viex.dwBuildNumber = lpVersionInformation->dwBuildNumber; 00216 viex.dwPlatformId = lpVersionInformation->dwPlatformId; 00217 viex.wServicePackMajor = lpVersionInformation->wServicePackMajor; 00218 viex.wServicePackMinor = lpVersionInformation->wServicePackMinor; 00219 viex.wSuiteMask = lpVersionInformation->wSuiteMask; 00220 viex.wProductType = lpVersionInformation->wProductType; 00221 viex.wReserved = lpVersionInformation->wReserved; 00222 return VerifyVersionInfoW(&viex, dwTypeMask, dwlConditionMask); 00223 } Generated on Sun May 27 2012 04:19:18 for ReactOS by
1.7.6.1
|