From: Eric Kohl Date: Sat, 3 Nov 2007 11:02:31 +0000 (+0000) Subject: Implement removal of environment variables by removing all environment variables... X-Git-Tag: backups/curicon_rewrite@32816~1392 X-Git-Url: https://git.reactos.org/?p=reactos.git;a=commitdiff_plain;h=495c4b799c3ed8568c28e50bd5225d4365fb58b4 Implement removal of environment variables by removing all environment variables from the registry and re-adding the stored ones. svn path=/trunk/; revision=30086 --- diff --git a/reactos/dll/cpl/sysdm/environment.c b/reactos/dll/cpl/sysdm/environment.c index 9460f146852..dc57f52399e 100644 --- a/reactos/dll/cpl/sysdm/environment.c +++ b/reactos/dll/cpl/sysdm/environment.c @@ -484,7 +484,14 @@ SetAllVars(HWND hwndDlg, PVARIABLE_DATA VarData; LV_ITEM lvi; INT iItem; - HKEY hk; + HKEY hKey; + DWORD dwValueCount; + DWORD dwMaxValueNameLength; + LPTSTR *aValueArray; + DWORD dwNameLength; + DWORD i; + TCHAR szBuffer[256]; + LPTSTR lpBuffer; memset(&lvi, 0x00, sizeof(lvi)); @@ -504,12 +511,78 @@ SetAllVars(HWND hwndDlg, REG_OPTION_NON_VOLATILE, KEY_WRITE | KEY_READ, NULL, - &hk, + &hKey, NULL)) { return; } + /* Get the number of values and the maximum value name length */ + if (RegQueryInfoKey(hKey, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + &dwValueCount, + &dwMaxValueNameLength, + NULL, + NULL, + NULL)) + { + RegCloseKey(hKey); + return; + } + + if (dwValueCount > 0) + { + /* Allocate the value array */ + aValueArray = GlobalAlloc(GPTR, dwValueCount * sizeof(LPTSTR)); + if (aValueArray != NULL) + { + /* Get all value names */ + for (i = 0; i < dwValueCount; i++) + { + dwNameLength = 256; + if (!RegEnumValue(hKey, + i, + szBuffer, + &dwNameLength, + NULL, + NULL, + NULL, + NULL)) + { + /* Allocate a value name buffer, fill it and attach it to the array */ + lpBuffer = (LPTSTR)GlobalAlloc(GPTR, (dwNameLength + 1) * sizeof(TCHAR)); + if (lpBuffer != NULL) + { + _tcscpy(lpBuffer, szBuffer); + aValueArray[i] = lpBuffer; + } + } + } + + /* Delete all values */ + for (i = 0; i < dwValueCount; i++) + { + if (aValueArray[i] != NULL) + { + /* Delete the value*/ + RegDeleteValue(hKey, + aValueArray[i]); + + /* Free the value name */ + GlobalFree(aValueArray[i]); + } + } + + /* Free the value array */ + GlobalFree(aValueArray); + } + } + /* Loop through all variables */ while(ListView_GetItem(hwndListView, &lvi)) { @@ -518,14 +591,14 @@ SetAllVars(HWND hwndDlg, if (VarData != NULL) { /* Set the new value */ - if (RegSetValueEx(hk, + if (RegSetValueEx(hKey, VarData->lpName, 0, VarData->dwType, (LPBYTE)VarData->lpRawValue, (DWORD)(_tcslen(VarData->lpRawValue) + 1) * sizeof(TCHAR))) { - RegCloseKey(hk); + RegCloseKey(hKey); return; } } @@ -535,7 +608,7 @@ SetAllVars(HWND hwndDlg, lvi.iItem = ++iItem; } - RegCloseKey(hk); + RegCloseKey(hKey); }