Activation des modifications de schéma au niveau du contrôleur de schéma
par défaut, la modification du schéma est désactivée sur tous les contrôleurs de domaine Windows 2000. La possibilité de mettre à jour le schéma est contrôlée par la valeur de Registre suivante sur le contrôleur de domaine principal du schéma :
HKEY_LOCAL_MACHINE
System
CurrentControlSet
Services
NTDS
Parameters
Schema Update Allowed
Cette valeur de Registre est une valeur reg _ DWORD . Si cette valeur est absente ou si elle contient zéro (0), la modification du schéma est désactivée. Si cette valeur est présente et contient une valeur différente de zéro, la modification de schéma est activée.
Le composant logiciel enfichable MMC du gestionnaire de schémas offre à l’utilisateur la possibilité d’activer ou de désactiver manuellement la modification du schéma. La modification de schéma peut être activée ou désactivée par programme en modifiant cette valeur de Registre sur le contrôleur de domaine principal du schéma.
La fonction C++ suivante montre comment déterminer si le schéma peut être modifié sur un contrôleur de schéma spécifié.
HRESULT IsSchemaUpdateEnabled(
LPTSTR pszSchemaMasterComputerName,
BOOL *pfEnabled)
{
*pfEnabled = FALSE;
LPTSTR szPrefix = "\\\\";
LPTSTR pszPath = new TCHAR[lstrlen(szPrefix) +
lstrlen(pszSchemaMasterComputerName) + 1];
if(!pszPath)
{
return E_OUTOFMEMORY;
}
HRESULT hr = E_FAIL;
LONG lReturn;
HKEY hKeyMachine;
tcscpy_s(pszPath, szPrefix);
tcscat_s(pszPath, pszSchemaMasterComputerName);
lReturn = RegConnectRegistry(
pszPath,
HKEY_LOCAL_MACHINE,
&hKeyMachine);
delete [] pszPath;
if (ERROR_SUCCESS == lReturn)
{
HKEY hKeyParameters;
LPTSTR szKeyPath =
TEXT("System\\CurrentControlSet\\Services\\NTDS\\Parameters");
LPTSTR szValueName = TEXT("Schema Update Allowed");
lReturn = RegOpenKeyEx(
hKeyMachine,
szKeyPath,
0,
KEY_READ,
&hKeyParameters);
if (ERROR_SUCCESS == lReturn)
{
DWORD dwType;
DWORD dwValue;
DWORD dwSize;
dwSize = sizeof(dwValue);
lReturn = RegQueryValueEx(
hKeyParameters,
szValueName,
0,
&dwType,
(LPBYTE)&dwValue,
&dwSize);
if (ERROR_SUCCESS == lReturn)
{
*pfEnabled = (0 != dwValue);
hr = S_OK;
}
RegCloseKey(hKeyParameters);
}
RegCloseKey(hKeyMachine);
}
return hr;
}
La fonction C++ suivante montre comment activer ou désactiver la modification de schéma sur un contrôleur de schéma spécifié.
HRESULT EnableSchemaUpdate(
LPTSTR pszSchemaMasterComputerName,
BOOL fEnabled)
{
LPTSTR szPrefix = "\\\\";
LPTSTR pszPath = new TCHAR[lstrlen(szPrefix) +
lstrlen(pszSchemaMasterComputerName) + 1];
if(!pszPath)
{
return E_OUTOFMEMORY;
}
HRESULT hr = E_FAIL;
LONG lReturn;
HKEY hKeyMachine;
strcpy_s(pszPath, szPrefix);
strcat_s(pszPath, pszSchemaMasterComputerName);
lReturn = RegConnectRegistry(
pszPath,
HKEY_LOCAL_MACHINE,
&hKeyMachine);
delete [] pszPath;
if (ERROR_SUCCESS == lReturn)
{
HKEY hKeyParameters;
LPTSTR szRelKeyPath =
TEXT("System\\CurrentControlSet\\Services\\NTDS\\Parameters");
LPTSTR szValueName = TEXT("Schema Update Allowed");
lReturn = RegOpenKeyEx(
hKeyMachine,
szRelKeyPath,
0,
KEY_SET_VALUE,
&hKeyParameters);
if (ERROR_SUCCESS == lReturn)
{
DWORD dwValue;
DWORD dwSize;
if(fEnabled)
{
dwValue = 1;
}
else
{
dwValue = 0;
}
dwSize = sizeof(dwValue);
lReturn = RegSetValueEx(
hKeyParameters,
szValueName,
0L,
REG_DWORD,
(LPBYTE)&dwValue,
dwSize);
if (ERROR_SUCCESS == lReturn)
{
hr = S_OK;
}
RegCloseKey(hKeyParameters);
}
RegCloseKey(hKeyMachine);
}
return hr;
}