test: prodtype.c File Reference

Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

# prodtype.c File Reference

`#include "ntrtlp.h"`

Go to the source code of this file.

## Functions

BOOLEAN | RtlGetNtProductType (OUT PNT_PRODUCT_TYPE NtProductType)

## Function Documentation

BOOLEAN RtlGetNtProductType | ( | OUT PNT_PRODUCT_TYPE | NtProductType | ) |

Definition at line 30 of file prodtype.c.

References DbgPrint, FALSE, KeyPath, L, NT_SUCCESS, NtClose(), NtOpenKey(), NtQueryValueKey(), NTSTATUS(), NULL, ObjectAttributes, RTL_PAGED_CODE, RtlAllocateHeap, RtlEqualUnicodeString(), RtlFreeHeap, RtlInitUnicodeString(), Status, TRUE, USHORT, and ValueName.

Referenced by RtlGetVersion().

    00036                    :
    00037
    00038     Returns the product type of the current system.
    00039
    00040 Arguments:
    00041
    00042     NtProductType - Returns the product type.  Either NtProductWinNt or
    00043         NtProductLanManNt.
    00044
    00045 Return Value:
    00046
    00047     TRUE on success, FALSE on failure
    00048     The product type will be set to WinNt on failure
    00049
    00050 --*/
    00051
    00052 {
    00053
    00054     NTSTATUS Status;
    00055     OBJECT_ATTRIBUTES ObjectAttributes;
    00056     HANDLE KeyHandle;
    00057     PKEY_VALUE_FULL_INFORMATION KeyValueInformation;
    00058     ULONG KeyValueInfoLength;
    00059     ULONG ResultLength;
    00060     UNICODE_STRING KeyPath;
    00061     UNICODE_STRING ValueName;
    00062     UNICODE_STRING Value;
    00063     UNICODE_STRING WinNtValue;
    00064     UNICODE_STRING LanmanNtValue;
    00065     UNICODE_STRING ServerNtValue;
    00066     BOOLEAN Result;
    00067
    00068     RTL_PAGED_CODE();
    00069
    00070     //
    00071     // if we are in gui setup mode, product type is read from the registry since
    00072     // gui setup mode is the only time product type can be changed.
    00073     // All other times, the "captured at boot" version of product type is used
    00074     //
    00075
    00076     if ( USER_SHARED_DATA->ProductTypeIsValid ) {
    00077         *NtProductType = USER_SHARED_DATA->NtProductType;
    00078         return TRUE;
    00079         }
    00080
    00081     //
    00082     // Prepare default value for failure case
    00083     //
    00084
    00085     *NtProductType = NtProductWinNt;
    00086     Result = FALSE;
    00087
    00088     RtlInitUnicodeString( &KeyPath, L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\ProductOptions" );
    00089     RtlInitUnicodeString( &ValueName, L"ProductType" );
    00090
    00091     InitializeObjectAttributes( &ObjectAttributes,
    00092                                 &KeyPath,
    00093                                 OBJ_CASE_INSENSITIVE,
    00094                                 NULL,
    00095                                 NULL
    00096                               );
    00097     Status = NtOpenKey( &KeyHandle,
    00098                         MAXIMUM_ALLOWED,
    00099                         &ObjectAttributes
    00100                       );
    00101     KeyValueInformation = NULL;
    00102     if (NT_SUCCESS( Status )) {
    00103         KeyValueInfoLength = 256;
    00104         KeyValueInformation = RtlAllocateHeap( RtlProcessHeap(), 0,
    00105                                                KeyValueInfoLength
    00106                                              );
    00107         if (KeyValueInformation == NULL) {
    00108             Status = STATUS_NO_MEMORY;
    00109         } else {
    00110             Status = NtQueryValueKey( KeyHandle,
    00111                                       &ValueName,
    00112                                       KeyValueFullInformation,
    00113                                       KeyValueInformation,
    00114                                       KeyValueInfoLength,
    00115                                       &ResultLength
    00116                                     );
    00117         }
    00118     } else {
    00119         KeyHandle = NULL;
    00120     }
    00121
    00122     if (NT_SUCCESS( Status ) && KeyValueInformation->Type == REG_SZ) {
    00123
    00124         //
    00125         // Decide which product we are installed as
    00126         //
    00127
    00128         Value.Buffer = (PWSTR)((PCHAR)KeyValueInformation + KeyValueInformation->DataOffset);
    00129         Value.Length = (USHORT)(KeyValueInformation->DataLength - sizeof( UNICODE_NULL ));
    00130         Value.MaximumLength = (USHORT)(KeyValueInformation->DataLength);
    00131         RtlInitUnicodeString(&WinNtValue, L"WinNt");
    00132         RtlInitUnicodeString(&LanmanNtValue, L"LanmanNt");
    00133         RtlInitUnicodeString(&ServerNtValue, L"ServerNt");
    00134
    00135         if (RtlEqualUnicodeString(&Value, &WinNtValue, TRUE)) {
    00136             *NtProductType = NtProductWinNt;
    00137             Result = TRUE;
    00138         } else if (RtlEqualUnicodeString(&Value, &LanmanNtValue, TRUE)) {
    00139             *NtProductType = NtProductLanManNt;
    00140             Result = TRUE;
    00141         } else if (RtlEqualUnicodeString(&Value, &ServerNtValue, TRUE)) {
    00142             *NtProductType = NtProductServer;
    00143             Result = TRUE;
    00144         } else {
    00145 #if DBG
    00146             DbgPrint("RtlGetNtProductType: Product type unrecognised <%wZ>\n", &Value);
    00147 #endif // DBG
    00148         }
    00149     } else {
    00150 #if DBG
    00151         DbgPrint("RtlGetNtProductType: %wZ\\%wZ not found or invalid type\n", &KeyPath, &ValueName );
    00152 #endif // DBG
    00153     }
    00154
    00155     //
    00156     // Clean up our resources.
    00157     //
    00158
    00159     if (KeyValueInformation != NULL) {
    00160         RtlFreeHeap( RtlProcessHeap(), 0, KeyValueInformation );
    00161     }
    00162
    00163     if (KeyHandle != NULL) {
    00164         NtClose( KeyHandle );
    00165     }
    00166
    00167     //
    00168     // Return result.
    00169     //
    00170
    00171     return(Result);
    00172
    00173
    00174
    00175
    00176
    00177
    00178
    00179
    00180
    00181
    00182
    00183
    00184 }
    }