[ros-diffs] [turner] 20048: Write the new environment vars to the registry. Fixes 987.

turner at svn.reactos.com turner at svn.reactos.com
Sun Dec 11 05:37:23 CET 2005


Write the new environment vars to the registry.  Fixes 987.
Modified: trunk/reactos/lib/cpl/sysdm/environment.c
  _____  

Modified: trunk/reactos/lib/cpl/sysdm/environment.c
--- trunk/reactos/lib/cpl/sysdm/environment.c	2005-12-11 00:07:56 UTC
(rev 20047)
+++ trunk/reactos/lib/cpl/sysdm/environment.c	2005-12-11 04:37:18 UTC
(rev 20048)
@@ -473,7 +473,71 @@

   }
 }
 
+VOID
+SetAllVars(HWND hwndDlg,
+           INT iDlgItem)
+{
+   HWND hwndListView;
+   PVARIABLE_DATA VarData;
+   LV_ITEM lvi;
+   INT iItem;
+   HKEY hk;
+   DWORD Type = 0;
 
+   memset(&lvi, 0x00, sizeof(lvi));
+
+   /* Get the handle to the list box with all system vars in it */
+   hwndListView = GetDlgItem(hwndDlg, iDlgItem);
+   /* first item is 0 */
+   iItem = 0;
+   /* set up struct to retreive item */
+   lvi.mask = LVIF_PARAM;
+   lvi.iItem = iItem;
+
+   /* Open or create the key */
+   if (RegCreateKeyEx((iDlgItem == IDC_SYSTEM_VARIABLE_LIST ?
HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER), 
+       (iDlgItem == IDC_SYSTEM_VARIABLE_LIST ?
_T("SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment") :
_T("Environment")), 
+       0, 
+       NULL, 
+       REG_OPTION_NON_VOLATILE,
+       KEY_WRITE | KEY_READ, 
+       NULL, 
+       &hk, 
+       NULL)) 
+   {
+      return;
+   }
+
+   /* loop through all system variables */
+   while(ListView_GetItem(hwndListView, &lvi))
+   {
+      /* Get the data in each item */
+      VarData = (PVARIABLE_DATA)lvi.lParam;
+      if (VarData != NULL)
+      {
+         /* Get the type */
+         RegQueryValueEx(hk,VarData->lpName,NULL,&Type,NULL,NULL);
+
+         /* Set the new value */
+         if (RegSetValueEx(hk,
+             VarData->lpName,
+             0,
+             Type,
+             (LPBYTE) VarData->lpRawValue,
+             (DWORD) (_tcsclen(VarData->lpRawValue)* sizeof(TCHAR))+1))
+         {
+            RegCloseKey(hk); 
+            return;
+         }
+      }
+      /* Fill struct for next item */
+      lvi.mask = LVIF_PARAM;
+      lvi.iItem = ++iItem;
+   }
+
+   RegCloseKey(hk);
+}
+
 /* Environment dialog procedure */
 INT_PTR CALLBACK
 EnvironmentDlgProc(HWND hwndDlg,
@@ -515,7 +579,8 @@
           return TRUE;
 
         case IDOK:
-          /* FIXME: Set environment variables in the registry */
+          SetAllVars(hwndDlg, IDC_USER_VARIABLE_LIST);
+          SetAllVars(hwndDlg, IDC_SYSTEM_VARIABLE_LIST);
 
         case IDCANCEL:
           ReleaseListViewItems(hwndDlg, IDC_USER_VARIABLE_LIST);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.reactos.org/pipermail/ros-diffs/attachments/20051211/36d53f25/attachment.html


More information about the Ros-diffs mailing list