Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1094 lines
34 KiB

  1. //*********************************************************************
  2. //* Microsoft Windows **
  3. //* Copyright(c) Microsoft Corp., 1993 **
  4. //*********************************************************************
  5. #include "admincfg.h"
  6. UINT SaveUserData(USERDATA * pUserData,TABLEENTRY * pTableEntry,HKEY hkeyRoot,
  7. CHAR * pszCurrentKeyName);
  8. UINT SaveOneEntry(USERDATA * pUserData,TABLEENTRY * pTableEntry,HKEY hkeyRoot,
  9. CHAR * pszCurrentKeyName,BOOL fErase);
  10. UINT SavePolicy(USERDATA * pUserData,TABLEENTRY * pTableEntry,HKEY hkeyRoot,
  11. CHAR * pszCurrentKeyName);
  12. UINT SaveSettings(USERDATA * pUserData,TABLEENTRY * pTableEntry,HKEY hkeyRoot,
  13. CHAR * pszCurrentKeyName,BOOL fErase);
  14. UINT SaveListboxData(USERDATA * pUserData,TABLEENTRY * pTableEntry,HKEY hkeyRoot,
  15. CHAR * pszCurrentKeyName,BOOL fErase,BOOL fMarkDeleted);
  16. UINT WriteStandardValue(HKEY hkeyRoot,CHAR * pszKeyName,CHAR * pszValueName,
  17. TABLEENTRY * pTableEntry,DWORD dwData,BOOL fErase,BOOL fWriteZero);
  18. UINT WriteCustomValue(HKEY hkeyRoot,CHAR * pszKeyName,CHAR * pszValueName,
  19. STATEVALUE * pStateValue,BOOL fErase);
  20. UINT WriteCustomValue_W(HKEY hkeyRoot,CHAR * pszKeyName,CHAR * pszValueName,
  21. CHAR * pszValue,DWORD dwValue,DWORD dwFlags,BOOL fErase);
  22. UINT WriteActionList(HKEY hkeyRoot,ACTIONLIST * pActionList,
  23. CHAR *pszCurrentKeyName,BOOL fErase);
  24. UINT WriteDropdownValue(TABLEENTRY * pTableEntry,HKEY hkeyRoot,
  25. CHAR * pszCurrentKeyName,CHAR * pszValueName,UINT nValue,BOOL fErase);
  26. UINT ProcessPolicyActionLists(HKEY hkeyRoot,POLICY * pPolicy,
  27. CHAR * pszCurrentKeyName,UINT uState,BOOL fErase);
  28. UINT ProcessCheckboxActionLists(HKEY hkeyRoot,TABLEENTRY * pTableEntry,
  29. CHAR * pszCurrentKeyName,DWORD dwVal,BOOL fErase);
  30. BOOL GetCloneData(HGLOBAL hClone,UINT uDataIndex,DWORD *pdwData);
  31. UINT DeleteSettings(USERDATA * pUserData,TABLEENTRY * pTableEntry,HKEY hkeyRoot,
  32. CHAR * pszCurrentKeyName);
  33. /*******************************************************************
  34. NAME: SaveFile
  35. SYNOPSIS: Saves the active policy file
  36. NOTES: Save is non-destructive; e.g. we don't wipe out the file
  37. and write it from scratch, because there may be stuff
  38. in the file that we're not aware of. If this is a previously
  39. saved file, we look at the clones of users that contain
  40. their initial states and tip-toe through writing out
  41. the data.
  42. ********************************************************************/
  43. BOOL SaveFile(CHAR * pszFilename,HWND hwndApp,HWND hwndList)
  44. {
  45. HKEY hkeyMain=NULL,hkeyUser=NULL,hkeyWorkstation=NULL,hkeyRoot,hkeyInstance;
  46. HKEY hkeyGroup=NULL,hkeyGroupPriority=NULL;
  47. UINT uRet=ERROR_SUCCESS,nIndex;
  48. HGLOBAL hUser;
  49. USERDATA * pUserData;
  50. TABLEENTRY * pTableEntry;
  51. USERHDR * pUserHdrDeleted;
  52. CHAR szMappedName[MAXNAMELEN+1];
  53. HCURSOR hOldCursor;
  54. OFSTRUCT of;
  55. HFILE hFile;
  56. // RegLoadKey returns totally coarse error codes, and will not
  57. // return any error if the file is on a read-only share on the network,
  58. // so open the file normally first to try to catch errors
  59. if ((hFile=OpenFile(pszFilename,&of,OF_READWRITE)) == HFILE_ERROR) {
  60. DisplayStandardError(hwndApp,pszFilename,IDS_ErrREGERR_SAVEKEY1,
  61. of.nErrCode);
  62. return FALSE;
  63. }
  64. _lclose(hFile);
  65. if ((uRet = MyRegLoadKey(HKEY_LOCAL_MACHINE,szTMPDATA,pszFilename))
  66. != ERROR_SUCCESS) {
  67. CHAR szFmt[REGBUFLEN],szMsg[REGBUFLEN+MAX_PATH+1];
  68. LoadSz(IDS_ErrREGERR_LOADKEY,szFmt,sizeof(szFmt));
  69. wsprintf(szMsg,szFmt,pszFilename,uRet);
  70. MsgBoxSz(hwndApp,szMsg,MB_ICONEXCLAMATION,MB_OK);
  71. return FALSE;
  72. }
  73. // write the information to the local registry, then use RegSaveKey to
  74. // make it into a hive file.
  75. if ( (RegCreateKey(HKEY_LOCAL_MACHINE,szTMPDATA,&hkeyMain) !=
  76. ERROR_SUCCESS) ||
  77. (RegCreateKey(hkeyMain,szUSERS,&hkeyUser) != ERROR_SUCCESS) ||
  78. (RegCreateKey(hkeyMain,szWORKSTATIONS,&hkeyWorkstation)
  79. != ERROR_SUCCESS) ||
  80. (RegCreateKey(hkeyMain,szUSERGROUPS,&hkeyGroup) != ERROR_SUCCESS) ||
  81. (RegCreateKey(hkeyMain,szUSERGROUPDATA,&hkeyGroupPriority) != ERROR_SUCCESS)) {
  82. if (hkeyWorkstation) RegCloseKey(hkeyWorkstation);
  83. if (hkeyUser) RegCloseKey(hkeyUser);
  84. if (hkeyMain) RegCloseKey(hkeyMain);
  85. if (hkeyGroup) RegCloseKey(hkeyGroup);
  86. if (hkeyGroupPriority) RegCloseKey(hkeyGroupPriority);
  87. MsgBox(hwndApp,IDS_ErrREGERR_CANTSAVE,MB_ICONEXCLAMATION,MB_OK);
  88. return FALSE;
  89. }
  90. hOldCursor=SetCursor(LoadCursor(NULL,IDC_WAIT));
  91. for (nIndex = 0;nIndex < (UINT) ListView_GetItemCount(hwndList) &&
  92. (uRet == ERROR_SUCCESS);nIndex++) {
  93. if (hUser = (HGLOBAL) LongToHandle(ListView_GetItemParm(hwndList,nIndex))) {
  94. if (!(pUserData = (USERDATA *) GlobalLock(hUser))) {
  95. SetCursor(hOldCursor);
  96. MsgBox(hwndApp,IDS_ErrOUTOFMEMORY,MB_ICONEXCLAMATION,MB_OK);
  97. uRet = ERROR_NOT_ENOUGH_MEMORY;
  98. break;
  99. }
  100. if (pUserData->hdr.dwType & UT_USER) {
  101. pTableEntry = gClassList.pUserCategoryList;
  102. hkeyRoot = (pUserData->hdr.dwType & UF_GROUP ? hkeyGroup :
  103. hkeyUser);
  104. } else {
  105. pTableEntry = gClassList.pMachineCategoryList;
  106. hkeyRoot = hkeyWorkstation;
  107. }
  108. // create a key with user/machine name
  109. MapUserName(pUserData->hdr.szName,szMappedName);
  110. if ((uRet=RegCreateKey(hkeyRoot,szMappedName,
  111. &hkeyInstance)) != ERROR_SUCCESS)
  112. break;
  113. // build a tree of information to be merged under user/machine
  114. // name
  115. uRet=SaveUserData(pUserData,pTableEntry,hkeyInstance,NULL);
  116. GlobalUnlock(hUser);
  117. // create a clone for this user with last saved state
  118. CloneUser(hUser);
  119. RegCloseKey(hkeyInstance);
  120. }
  121. }
  122. #ifdef INCL_GROUP_SUPPORT
  123. SaveGroupPriorityList(hkeyGroupPriority);
  124. #endif
  125. // delete any users that have been marked as deleted
  126. nIndex=0;
  127. while (pUserHdrDeleted = GetDeletedUser(nIndex)) {
  128. HKEY hkeyDelRoot=NULL;
  129. switch (pUserHdrDeleted->dwType) {
  130. case UT_USER:
  131. hkeyDelRoot = hkeyUser;
  132. break;
  133. case UT_MACHINE:
  134. hkeyDelRoot = hkeyWorkstation;
  135. break;
  136. #ifdef INCL_GROUP_SUPPORT
  137. case UT_USER | UF_GROUP:
  138. hkeyDelRoot = hkeyGroup;
  139. break;
  140. #endif
  141. default:
  142. continue; // shouldn't happen, but just in case
  143. }
  144. // map the user name to map "default user" to ".default", etc.
  145. MapUserName(pUserHdrDeleted->szName,szMappedName);
  146. MyRegDeleteKey(hkeyDelRoot,szMappedName);
  147. nIndex++;
  148. }
  149. ClearDeletedUserList();
  150. RegCloseKey(hkeyUser);
  151. RegCloseKey(hkeyWorkstation);
  152. RegCloseKey(hkeyMain);
  153. RegCloseKey(hkeyGroup);
  154. RegCloseKey(hkeyGroupPriority);
  155. MyRegUnLoadKey(HKEY_LOCAL_MACHINE,szTMPDATA);
  156. RegFlushKey(HKEY_LOCAL_MACHINE);
  157. SetCursor(hOldCursor);
  158. SetFileAttributes(pszFilename,FILE_ATTRIBUTE_ARCHIVE);
  159. if (uRet != ERROR_SUCCESS) {
  160. if (uRet == ERROR_NOT_ENOUGH_MEMORY) {
  161. MsgBox(hwndApp,IDS_ErrOUTOFMEMORY,MB_ICONEXCLAMATION,MB_OK);
  162. } else {
  163. CHAR szFmt[REGBUFLEN],szMsg[REGBUFLEN+MAX_PATH+1];
  164. LoadSz(IDS_ErrREGERR_SAVEKEY,szFmt,sizeof(szFmt));
  165. wsprintf(szMsg,szFmt,pszFilename,uRet);
  166. MsgBoxSz(hwndApp,szMsg,MB_ICONEXCLAMATION,MB_OK);
  167. }
  168. }
  169. return (uRet == ERROR_SUCCESS);
  170. }
  171. /*******************************************************************
  172. NAME: SaveToRegistry
  173. SYNOPSIS: Writes loaded information to the registry
  174. ********************************************************************/
  175. BOOL SaveToRegistry(HWND hwndApp,HWND hwndList)
  176. {
  177. HKEY hkeyUser=NULL,hkeyWorkstation=NULL,hkeyRoot;
  178. UINT uRet = ERROR_SUCCESS,nIndex;
  179. HGLOBAL hUser;
  180. USERDATA * pUserData=NULL;
  181. TABLEENTRY * pTableEntry;
  182. HCURSOR hOldCursor;
  183. if ((RegOpenKeyEx(hkeyVirtHCU,NULL,0,KEY_ALL_ACCESS,&hkeyUser) != ERROR_SUCCESS) ||
  184. (RegOpenKeyEx(hkeyVirtHLM,NULL,0,KEY_ALL_ACCESS,&hkeyWorkstation) != ERROR_SUCCESS)) {
  185. MsgBox(hwndApp,IDS_ErrCANTOPENREGISTRY,MB_ICONEXCLAMATION,MB_OK);
  186. if (hkeyUser) RegCloseKey(hkeyUser);
  187. if (hkeyWorkstation) RegCloseKey(hkeyWorkstation);
  188. return FALSE;
  189. }
  190. hOldCursor=SetCursor(LoadCursor(NULL,IDC_WAIT));
  191. for (nIndex = 0;nIndex < (UINT) ListView_GetItemCount(hwndList)
  192. && (uRet == ERROR_SUCCESS);nIndex++) {
  193. if (hUser = (HGLOBAL) LongToHandle(ListView_GetItemParm(hwndList,nIndex))) {
  194. if (!(pUserData = (USERDATA *) GlobalLock(hUser))) {
  195. SetCursor(hOldCursor);
  196. MsgBox(hwndApp,IDS_ErrOUTOFMEMORY,MB_ICONEXCLAMATION,MB_OK);
  197. uRet = ERROR_NOT_ENOUGH_MEMORY;
  198. break;
  199. }
  200. if (pUserData->hdr.dwType & UT_USER) {
  201. pTableEntry = gClassList.pUserCategoryList;
  202. hkeyRoot = hkeyUser;
  203. } else {
  204. pTableEntry = gClassList.pMachineCategoryList;
  205. hkeyRoot = hkeyWorkstation;
  206. }
  207. // build a tree of information to be merged under user/machine
  208. // name
  209. uRet=SaveUserData(pUserData,pTableEntry,hkeyRoot,NULL);
  210. GlobalUnlock(hUser);
  211. }
  212. }
  213. RegCloseKey(hkeyUser);
  214. RegCloseKey(hkeyWorkstation);
  215. SetCursor(hOldCursor);
  216. if (uRet != ERROR_SUCCESS) {
  217. if (uRet == ERROR_NOT_ENOUGH_MEMORY) {
  218. MsgBox(hwndApp,IDS_ErrOUTOFMEMORY,MB_ICONEXCLAMATION,MB_OK);
  219. } else {
  220. CHAR szMsg[REGBUFLEN+1];
  221. wsprintf(szMsg,"%d",uRet);
  222. MsgBoxParam(hwndApp,IDS_ErrREGERR_SAVE,szMsg,MB_ICONEXCLAMATION,MB_OK);
  223. }
  224. }
  225. return (uRet == ERROR_SUCCESS);
  226. }
  227. /*******************************************************************
  228. NAME: SaveUserData
  229. SYNOPSIS: Saves one user to file
  230. ********************************************************************/
  231. UINT SaveUserData(USERDATA * pUserData,TABLEENTRY * pTableEntry,HKEY hkeyRoot,
  232. CHAR * pszCurrentKeyName)
  233. {
  234. UINT uRet=ERROR_SUCCESS;
  235. while (pTableEntry && (uRet == ERROR_SUCCESS)) {
  236. uRet = SaveOneEntry(pUserData,pTableEntry,hkeyRoot,
  237. pszCurrentKeyName,FALSE);
  238. pTableEntry = pTableEntry->pNext;
  239. }
  240. return uRet;
  241. }
  242. /*******************************************************************
  243. NAME: SaveOneEntry
  244. SYNOPSIS: Saves one entry (category, policy, or part) to
  245. file, calls SaveUserData for child entries
  246. ********************************************************************/
  247. UINT SaveOneEntry(USERDATA * pUserData,TABLEENTRY * pTableEntry,HKEY hkeyRoot,
  248. CHAR * pszCurrentKeyName,BOOL fErase)
  249. {
  250. UINT uRet;
  251. #if 0
  252. wsprintf(szDebugOut,"Saving... %s\r\n",GETNAMEPTR(pTableEntry));
  253. OutputDebugString(szDebugOut);
  254. #endif
  255. // if there is a key name for this entry, it becomes the "current"
  256. // key name-- it will be overridden if child entries specify their
  257. // own keys, otherwise it's the default key for children to use
  258. if (pTableEntry->uOffsetKeyName) {
  259. pszCurrentKeyName = GETKEYNAMEPTR(pTableEntry);
  260. }
  261. if ((pTableEntry->dwType == ETYPE_CATEGORY ||
  262. pTableEntry->dwType == ETYPE_ROOT) && (pTableEntry->pChild)) {
  263. // if entry is a category, recusively process sub-categories and policies
  264. if ((uRet=SaveUserData(pUserData,pTableEntry->pChild,
  265. hkeyRoot,pszCurrentKeyName)) != ERROR_SUCCESS) {
  266. return uRet;
  267. }
  268. } else if (pTableEntry->dwType == ETYPE_POLICY) {
  269. if ((uRet = SavePolicy(pUserData,pTableEntry,hkeyRoot,
  270. pszCurrentKeyName)) != ERROR_SUCCESS) {
  271. return uRet;
  272. }
  273. } else if ( (pTableEntry->dwType & ETYPE_MASK) == ETYPE_SETTING
  274. && !(pTableEntry->dwType & STYPE_TEXT)) {
  275. if ((uRet = SaveSettings(pUserData,pTableEntry,hkeyRoot,
  276. pszCurrentKeyName,fErase)) != ERROR_SUCCESS) {
  277. return uRet;
  278. }
  279. }
  280. return ERROR_SUCCESS;
  281. }
  282. /*******************************************************************
  283. NAME: SavePolicy
  284. SYNOPSIS: Saves policy to file
  285. ********************************************************************/
  286. UINT SavePolicy(USERDATA * pUserData,TABLEENTRY * pTableEntry,HKEY hkeyRoot,
  287. CHAR * pszCurrentKeyName)
  288. {
  289. UINT uState = pUserData->SettingData[((POLICY *)
  290. pTableEntry)->uDataIndex].uData;
  291. DWORD dwData;
  292. UINT uRet=ERROR_SUCCESS;
  293. CHAR * pszValueName = NULL;
  294. UINT uCloneState;
  295. // get the name of the value to write, if any
  296. if (((POLICY *) pTableEntry)->uOffsetValueName)
  297. pszValueName = GETVALUENAMEPTR(((POLICY *) pTableEntry));
  298. // if this policy is "on" or "off" write it to registry
  299. // (not if it's "indeterminate")
  300. if (uState == IMG_CHECKED || uState == IMG_UNCHECKED) {
  301. // write the value associated with the policy, if it has one
  302. if (pszValueName) {
  303. dwData = (uState == IMG_CHECKED ? 1 : 0);
  304. // write this key & value
  305. if (dwData && ((POLICY *) pTableEntry)->uOffsetValue_On) {
  306. uRet= WriteCustomValue(hkeyRoot,pszCurrentKeyName,pszValueName,
  307. (STATEVALUE *) ((CHAR *) pTableEntry + ((POLICY *)
  308. pTableEntry)->uOffsetValue_On),FALSE);
  309. } else if (!dwData && ((POLICY *) pTableEntry)->uOffsetValue_Off) {
  310. uRet= WriteCustomValue(hkeyRoot,pszCurrentKeyName,pszValueName,
  311. (STATEVALUE *) ((CHAR *) pTableEntry + ((POLICY *)
  312. pTableEntry)->uOffsetValue_Off),FALSE);
  313. }
  314. else uRet=WriteStandardValue(hkeyRoot,pszCurrentKeyName,pszValueName,
  315. pTableEntry,dwData,FALSE,FALSE);
  316. if (uRet != ERROR_SUCCESS)
  317. return uRet;
  318. }
  319. // process settings underneath this policy (if any) if
  320. // policy is turned on.
  321. if (pTableEntry->pChild) {
  322. if (uState == IMG_CHECKED) {
  323. if ((uRet=SaveUserData(pUserData,pTableEntry->pChild,
  324. hkeyRoot,pszCurrentKeyName))
  325. !=ERROR_SUCCESS)
  326. return uRet;
  327. } else {
  328. DeleteSettings(pUserData,pTableEntry->pChild,hkeyRoot,
  329. pszCurrentKeyName);
  330. }
  331. }
  332. // write out each key & value in the action list, if an action
  333. // list is specified
  334. if (GetCloneData(pUserData->hClone,((POLICY *)pTableEntry)->uDataIndex,
  335. &uCloneState)) {
  336. // if the clone state (initial state) is different from the
  337. // current state, erase action list for the clone's state
  338. if (uCloneState != uState) {
  339. uRet=ProcessPolicyActionLists(hkeyRoot,(POLICY *) pTableEntry,
  340. pszCurrentKeyName,uCloneState,TRUE);
  341. if (uRet != ERROR_SUCCESS)
  342. return uRet;
  343. }
  344. }
  345. uRet=ProcessPolicyActionLists(hkeyRoot,(POLICY *) pTableEntry,
  346. pszCurrentKeyName,uState,FALSE);
  347. if (uRet != ERROR_SUCCESS)
  348. return uRet;
  349. } else {
  350. // policy is "indeterminate"... which means do no delta.
  351. // However, since we save non-destructively, we need to delete
  352. // the value for this key if it is currently written in the file.
  353. // See if we have a clone for this user (clone will exist if there
  354. // is already a saved file that contains this user, clone will
  355. // reflect initial state). If the initial state was "checked"
  356. // or "unchecked", then erase the value from the file so that
  357. // the saved state is "nothing".
  358. TABLEENTRY * pTableEntryChild = pTableEntry->pChild;
  359. if (pszValueName) {
  360. CHAR szNewValueName[MAX_PATH+1];
  361. DeleteRegistryValue(hkeyRoot,pszCurrentKeyName,pszValueName);
  362. // delete the "delete" mark for this value, if there is one
  363. PrependValueName(pszValueName,VF_DELETE,szNewValueName,
  364. sizeof(szNewValueName));
  365. DeleteRegistryValue(hkeyRoot,pszCurrentKeyName,szNewValueName);
  366. }
  367. if (GetCloneData(pUserData->hClone,((POLICY *)pTableEntry)->uDataIndex,
  368. &uCloneState)) {
  369. // if the clone state (initial state) is different from the
  370. // current state, erase action list for the clone's state
  371. if (uCloneState != uState) {
  372. uRet=ProcessPolicyActionLists(hkeyRoot,(POLICY *) pTableEntry,
  373. pszCurrentKeyName,uCloneState,TRUE);
  374. if (uRet != ERROR_SUCCESS)
  375. return uRet;
  376. }
  377. }
  378. // erase values for any settings contained in this policy
  379. while (pTableEntryChild && (uRet == ERROR_SUCCESS)) {
  380. uRet = SaveOneEntry(pUserData,pTableEntryChild,hkeyRoot,
  381. pszCurrentKeyName,TRUE);
  382. pTableEntryChild = pTableEntryChild->pNext;
  383. }
  384. }
  385. return uRet;
  386. }
  387. /*******************************************************************
  388. NAME: SaveSettings
  389. SYNOPSIS: Saves settings entry to a file
  390. NOTES: if fErase is TRUE, settings and action lists are deleted from file
  391. ********************************************************************/
  392. UINT SaveSettings(USERDATA * pUserData,TABLEENTRY * pTableEntry,HKEY hkeyRoot,
  393. CHAR * pszCurrentKeyName,BOOL fErase)
  394. {
  395. UINT uRet = ERROR_SUCCESS,uOffset;
  396. CHAR * pszValueName = NULL,* pszValue;
  397. DWORD dwData,dwCloneData;
  398. CHAR * pObjectData = GETOBJECTDATAPTR(((SETTINGS *)pTableEntry));
  399. CHAR szNewValueName[MAX_PATH+1];
  400. // nothing to save for static text items
  401. if ((((SETTINGS *) pTableEntry)->dwType & STYPE_MASK) == STYPE_TEXT)
  402. return ERROR_SUCCESS;
  403. if (((SETTINGS *) pTableEntry)->uOffsetValueName) {
  404. pszValueName = GETVALUENAMEPTR(((SETTINGS *) pTableEntry));
  405. } else {
  406. return ERROR_NOT_ENOUGH_MEMORY; // should never happen, but bag out just in case
  407. }
  408. switch (pTableEntry->dwType & STYPE_MASK) {
  409. case STYPE_EDITTEXT:
  410. case STYPE_COMBOBOX:
  411. uOffset = pUserData->SettingData[((SETTINGS *)
  412. pTableEntry)->uDataIndex].uOffsetData;
  413. // add prefixes if appropriate
  414. PrependValueName(pszValueName,((SETTINGS *) pTableEntry)->dwFlags,
  415. szNewValueName,sizeof(szNewValueName));
  416. if (!fErase) {
  417. if (uOffset) {
  418. pszValue = ((STRDATA *) ((CHAR *) pUserData + uOffset))
  419. ->szData;
  420. } else {
  421. pszValue = (CHAR *) szNull;
  422. }
  423. uRet=WriteRegistryStringValue(hkeyRoot,pszCurrentKeyName,
  424. szNewValueName,pszValue,
  425. (((SETTINGS *) pTableEntry)->dwFlags & DF_EXPANDABLETEXT) ?
  426. TRUE : FALSE);
  427. if ((dwAppState & AS_POLICYFILE) && !(dwCmdLineFlags & CLF_DIALOGMODE)
  428. && !(((SETTINGS *) pTableEntry)->dwFlags & VF_DELETE)) {
  429. // delete the "delete" mark for this value, if there is one
  430. PrependValueName(pszValueName,VF_DELETE,szNewValueName,
  431. sizeof(szNewValueName));
  432. DeleteRegistryValue(hkeyRoot,pszCurrentKeyName,szNewValueName);
  433. }
  434. } else {
  435. DeleteRegistryValue(hkeyRoot,pszCurrentKeyName,szNewValueName);
  436. uRet = ERROR_SUCCESS;
  437. if (dwAppState & AS_POLICYFILE &&
  438. !(((SETTINGS *) pTableEntry)->dwFlags & VF_DELETE)) {
  439. // delete the "delete" mark for this value, if there is one
  440. PrependValueName(pszValueName,VF_DELETE,szNewValueName,
  441. sizeof(szNewValueName));
  442. DeleteRegistryValue(hkeyRoot,pszCurrentKeyName,szNewValueName);
  443. }
  444. }
  445. break;
  446. case STYPE_CHECKBOX:
  447. dwData = pUserData->SettingData[((SETTINGS *)
  448. pTableEntry)->uDataIndex].uData;
  449. if (dwData && ((CHECKBOXINFO *) pObjectData)->uOffsetValue_On) {
  450. uRet= WriteCustomValue(hkeyRoot,pszCurrentKeyName,pszValueName,
  451. (STATEVALUE *) ((CHAR *) pTableEntry + ((CHECKBOXINFO *)
  452. pObjectData)->uOffsetValue_On),fErase);
  453. } else if (!dwData && ((CHECKBOXINFO *) pObjectData)->uOffsetValue_Off) {
  454. uRet= WriteCustomValue(hkeyRoot,pszCurrentKeyName,pszValueName,
  455. (STATEVALUE *) ((CHAR *) pTableEntry + ((CHECKBOXINFO *)
  456. pObjectData)->uOffsetValue_Off),fErase);
  457. }
  458. else uRet=WriteStandardValue(hkeyRoot,pszCurrentKeyName,pszValueName,
  459. pTableEntry,dwData,fErase,FALSE);
  460. if (uRet == ERROR_SUCCESS) {
  461. // erase old actionlists if changed
  462. if (GetCloneData(pUserData->hClone,((SETTINGS *)pTableEntry)->uDataIndex,
  463. &dwCloneData)) {
  464. ProcessCheckboxActionLists(hkeyRoot,pTableEntry,
  465. pszCurrentKeyName,dwCloneData,TRUE);
  466. }
  467. ProcessCheckboxActionLists(hkeyRoot,pTableEntry,
  468. pszCurrentKeyName,dwData,fErase);
  469. }
  470. break;
  471. case STYPE_NUMERIC:
  472. dwData = pUserData->SettingData[((SETTINGS *)
  473. pTableEntry)->uDataIndex].uData;
  474. uRet=WriteStandardValue(hkeyRoot,pszCurrentKeyName,pszValueName,
  475. pTableEntry,dwData,fErase,TRUE);
  476. break;
  477. case STYPE_DROPDOWNLIST:
  478. dwData = pUserData->SettingData[((SETTINGS *)
  479. pTableEntry)->uDataIndex].uData;
  480. if (GetCloneData(pUserData->hClone,((SETTINGS *)pTableEntry)->uDataIndex,
  481. &dwCloneData)) {
  482. // erase old value if changed
  483. if (dwData != dwCloneData && dwCloneData != NO_DATA_INDEX)
  484. uRet=WriteDropdownValue(pTableEntry,hkeyRoot,pszCurrentKeyName,
  485. pszValueName,dwCloneData,TRUE);
  486. if (uRet != ERROR_SUCCESS)
  487. return uRet;
  488. }
  489. // write new value
  490. if (dwData == NO_DATA_INDEX) {
  491. if (dwAppState & AS_POLICYFILE &&
  492. !(((SETTINGS *) pTableEntry)->dwFlags & VF_DELETE)) {
  493. // delete the "delete" mark for this value, if there is one
  494. PrependValueName(pszValueName,VF_DELETE,szNewValueName,
  495. sizeof(szNewValueName));
  496. DeleteRegistryValue(hkeyRoot,pszCurrentKeyName,szNewValueName);
  497. }
  498. uRet = ERROR_SUCCESS;
  499. }
  500. else
  501. uRet=WriteDropdownValue(pTableEntry,hkeyRoot,pszCurrentKeyName,
  502. pszValueName,dwData,fErase);
  503. break;
  504. case STYPE_LISTBOX:
  505. uRet=SaveListboxData(pUserData,pTableEntry,hkeyRoot,pszCurrentKeyName,
  506. fErase,FALSE);
  507. break;
  508. }
  509. #ifdef DEBUG
  510. if (uRet != ERROR_SUCCESS) {
  511. wsprintf(szDebugOut,"ADMINCFG: registry write returned %d\r\n",uRet);
  512. OutputDebugString(szDebugOut);
  513. }
  514. #endif
  515. return uRet;
  516. }
  517. UINT ProcessPolicyActionLists(HKEY hkeyRoot,POLICY * pPolicy,
  518. CHAR * pszCurrentKeyName,UINT uState,BOOL fErase)
  519. {
  520. if ((uState == IMG_CHECKED) && (pPolicy->uOffsetActionList_On)) {
  521. return WriteActionList(hkeyRoot,(ACTIONLIST *)
  522. ( (CHAR *) pPolicy + pPolicy->uOffsetActionList_On),pszCurrentKeyName,
  523. fErase);
  524. } else if ((uState == IMG_UNCHECKED) && pPolicy->uOffsetActionList_Off) {
  525. return WriteActionList(hkeyRoot,(ACTIONLIST *)
  526. ( (CHAR *) pPolicy + pPolicy->uOffsetActionList_Off),
  527. pszCurrentKeyName,fErase);
  528. }
  529. return ERROR_SUCCESS;
  530. }
  531. UINT ProcessCheckboxActionLists(HKEY hkeyRoot,TABLEENTRY * pTableEntry,
  532. CHAR * pszCurrentKeyName,DWORD dwData,BOOL fErase)
  533. {
  534. CHAR * pObjectData = GETOBJECTDATAPTR(((SETTINGS *)pTableEntry));
  535. UINT uOffsetActionList_On,uOffsetActionList_Off,uRet=ERROR_SUCCESS;
  536. uOffsetActionList_On = ((CHECKBOXINFO *) pObjectData)
  537. ->uOffsetActionList_On;
  538. uOffsetActionList_Off = ((CHECKBOXINFO *) pObjectData)
  539. ->uOffsetActionList_Off;
  540. if (dwData && uOffsetActionList_On) {
  541. uRet = WriteActionList(hkeyRoot,(ACTIONLIST *)
  542. ((CHAR *) pTableEntry + uOffsetActionList_On),
  543. pszCurrentKeyName,fErase);
  544. } else if (!dwData && uOffsetActionList_Off) {
  545. uRet = WriteActionList(hkeyRoot,(ACTIONLIST *)
  546. ((CHAR *) pTableEntry + uOffsetActionList_Off),
  547. pszCurrentKeyName,fErase);
  548. }
  549. return uRet;
  550. }
  551. UINT WriteCustomValue_W(HKEY hkeyRoot,CHAR * pszKeyName,CHAR * pszValueName,
  552. CHAR * pszValue,DWORD dwValue,DWORD dwFlags,BOOL fErase)
  553. {
  554. UINT uRet=ERROR_SUCCESS;
  555. CHAR szNewValueName[MAX_PATH+1];
  556. // first: "clean house" by deleting both the specified value name,
  557. // and the value name with the delete (**del.) prefix (if writing to policy
  558. // file). Then write the appropriate version back out if need be
  559. if (dwAppState & AS_POLICYFILE) {
  560. // delete the "delete" mark for this value, if there is one
  561. PrependValueName(pszValueName,VF_DELETE,szNewValueName,
  562. sizeof(szNewValueName));
  563. DeleteRegistryValue(hkeyRoot,pszKeyName,szNewValueName);
  564. }
  565. // add prefixes if appropriate
  566. PrependValueName(pszValueName,(dwFlags & ~VF_DELETE),szNewValueName,
  567. sizeof(szNewValueName));
  568. DeleteRegistryValue(hkeyRoot,pszKeyName,szNewValueName);
  569. if (fErase) {
  570. // just need to delete value, done above
  571. uRet = ERROR_SUCCESS;
  572. } else if (dwFlags & VF_ISNUMERIC) {
  573. uRet=WriteRegistryDWordValue(hkeyRoot,pszKeyName,
  574. szNewValueName,dwValue);
  575. } else if (dwFlags & VF_DELETE) {
  576. // need to delete value (done above) and mark as deleted if writing
  577. // to policy file
  578. uRet = ERROR_SUCCESS;
  579. if ((dwAppState & AS_POLICYFILE) && !(dwCmdLineFlags & CLF_DIALOGMODE)) {
  580. PrependValueName(pszValueName,VF_DELETE,szNewValueName,
  581. sizeof(szNewValueName));
  582. uRet=WriteRegistryStringValue(hkeyRoot,pszKeyName,
  583. szNewValueName,(CHAR *) szNOVALUE, FALSE);
  584. }
  585. } else {
  586. uRet = WriteRegistryStringValue(hkeyRoot,pszKeyName,
  587. szNewValueName,pszValue,
  588. (dwFlags & DF_EXPANDABLETEXT) ? TRUE : FALSE);
  589. }
  590. return uRet;
  591. }
  592. UINT WriteCustomValue(HKEY hkeyRoot,CHAR * pszKeyName,CHAR * pszValueName,
  593. STATEVALUE * pStateValue,BOOL fErase)
  594. {
  595. // pull info out of STATEVALUE struct and call worker function
  596. return WriteCustomValue_W(hkeyRoot,pszKeyName,pszValueName,
  597. pStateValue->szValue,pStateValue->dwValue,pStateValue->dwFlags,
  598. fErase);
  599. }
  600. // writes a numeric value given root key, key name and value name. The specified
  601. // value is removed if fErase is TRUE. Normally if the data (dwData) is zero
  602. // the value will be deleted, but if fWriteZero is TRUE then the value will
  603. // be written as zero if the data is zero.
  604. UINT WriteStandardValue(HKEY hkeyRoot,CHAR * pszKeyName,CHAR * pszValueName,
  605. TABLEENTRY * pTableEntry,DWORD dwData,BOOL fErase,BOOL fWriteZero)
  606. {
  607. UINT uRet=ERROR_SUCCESS;
  608. CHAR szNewValueName[MAX_PATH+1];
  609. // first: "clean house" by deleting both the specified value name,
  610. // and the value name with the delete (**del.) prefix (if writing to policy
  611. // file). Then write the appropriate version back out if need be
  612. if (dwAppState & AS_POLICYFILE) {
  613. // delete the "delete" mark for this value, if there is one
  614. PrependValueName(pszValueName,VF_DELETE,szNewValueName,
  615. sizeof(szNewValueName));
  616. DeleteRegistryValue(hkeyRoot,pszKeyName,szNewValueName);
  617. }
  618. DeleteRegistryValue(hkeyRoot,pszKeyName,pszValueName);
  619. if (fErase) {
  620. // just need to delete value, done above
  621. uRet = ERROR_SUCCESS;
  622. } else if ( ((SETTINGS *) pTableEntry)->dwFlags & DF_TXTCONVERT) {
  623. // if specified, save value as text
  624. CHAR szNum[11];
  625. wsprintf(szNum,"%lu",dwData);
  626. PrependValueName(pszValueName,((SETTINGS *)pTableEntry)->dwFlags,
  627. szNewValueName,sizeof(szNewValueName));
  628. uRet = WriteRegistryStringValue(hkeyRoot,pszKeyName,
  629. szNewValueName,szNum, FALSE);
  630. } else {
  631. if (!dwData && !fWriteZero) {
  632. // if value is 0, delete the value (done above), and mark
  633. // it as deleted if writing to policy file
  634. uRet = ERROR_SUCCESS;
  635. if ((dwAppState & AS_POLICYFILE) && !(dwCmdLineFlags & CLF_DIALOGMODE)) {
  636. PrependValueName(pszValueName,VF_DELETE,szNewValueName,
  637. sizeof(szNewValueName));
  638. uRet=WriteRegistryStringValue(hkeyRoot,pszKeyName,
  639. szNewValueName,(CHAR *) szNOVALUE, FALSE);
  640. }
  641. } else {
  642. // save value as binary
  643. PrependValueName(pszValueName,((SETTINGS *)pTableEntry)->dwFlags,
  644. szNewValueName,sizeof(szNewValueName));
  645. uRet=WriteRegistryDWordValue(hkeyRoot,pszKeyName,
  646. szNewValueName,dwData);
  647. }
  648. }
  649. return uRet;
  650. }
  651. /*******************************************************************
  652. NAME: WriteDropdownValue
  653. SYNOPSIS: Writes (or deletes) the value corresponding to the
  654. nValue selection from a drop-down list, and writes
  655. (or deletes) the items in associated action list
  656. if there is one.
  657. NOTES: if fErase is TRUE, deletes value & action list.
  658. ********************************************************************/
  659. UINT WriteDropdownValue(TABLEENTRY * pTableEntry,HKEY hkeyRoot,
  660. CHAR * pszCurrentKeyName,CHAR * pszValueName,UINT nValue,BOOL fErase)
  661. {
  662. DROPDOWNINFO * pddi = (DROPDOWNINFO *)
  663. GETOBJECTDATAPTR( ((SETTINGS *) pTableEntry));
  664. UINT nIndex = 0,uRet=ERROR_SUCCESS;
  665. // walk the chain of DROPDOWNINFO structs to find the entry that
  666. // we want to write. (for value n, find the nth struct)
  667. while (nIndex < nValue) {
  668. // selected val is higher than # of structs in chain,
  669. // should never happen but check just in case...
  670. if (!pddi->uOffsetNextDropdowninfo) {
  671. return ERROR_NOT_ENOUGH_MEMORY;
  672. }
  673. pddi = (DROPDOWNINFO *)
  674. ((CHAR *) pTableEntry + pddi->uOffsetNextDropdowninfo);
  675. nIndex++;
  676. }
  677. uRet=WriteCustomValue_W(hkeyRoot,pszCurrentKeyName,pszValueName,
  678. (CHAR *) pTableEntry+pddi->uOffsetValue,pddi->dwValue,pddi->dwFlags,
  679. fErase);
  680. if (uRet == ERROR_SUCCESS && pddi->uOffsetActionList) {
  681. uRet=WriteActionList(hkeyRoot,(ACTIONLIST *) ( (CHAR *)
  682. pTableEntry + pddi->uOffsetActionList),pszCurrentKeyName,
  683. fErase);
  684. }
  685. return uRet;
  686. }
  687. /*******************************************************************
  688. NAME: WriteActionList
  689. SYNOPSIS: Writes (or deletes) a list of key name\value name\value
  690. triplets as specified in an ACTIONLIST struct
  691. NOTES: if fErase is TRUE, deletes every value in list
  692. ********************************************************************/
  693. UINT WriteActionList(HKEY hkeyRoot,ACTIONLIST * pActionList,
  694. CHAR *pszCurrentKeyName,BOOL fErase)
  695. {
  696. UINT nCount;
  697. CHAR * pszValueName;
  698. CHAR * pszValue=NULL;
  699. UINT uRet;
  700. ACTION * pAction = pActionList->Action;
  701. for (nCount=0;nCount < pActionList->nActionItems; nCount++) {
  702. // not every action in the list has to have a key name. But if one
  703. // is specified, use it and it becomes the current key name for the
  704. // list until we encounter another one.
  705. if (pAction->uOffsetKeyName) {
  706. pszCurrentKeyName = (CHAR *) pActionList + pAction->uOffsetKeyName;
  707. }
  708. // every action must have a value name, enforced at parse time
  709. pszValueName = (CHAR *) pActionList + pAction->uOffsetValueName;
  710. // string values have a string elsewhere in buffer
  711. if (!pAction->dwFlags && pAction->uOffsetValue) {
  712. pszValue = (CHAR *) pActionList + pAction->uOffsetValue;
  713. }
  714. // write the value in list
  715. uRet=WriteCustomValue_W(hkeyRoot,pszCurrentKeyName,pszValueName,
  716. pszValue,pAction->dwValue,pAction->dwFlags,fErase);
  717. if (uRet != ERROR_SUCCESS) return uRet;
  718. pAction = (ACTION*) ((CHAR *) pActionList + pAction->uOffsetNextAction);
  719. }
  720. return ERROR_SUCCESS;
  721. }
  722. /*******************************************************************
  723. NAME: GetCloneData
  724. SYNOPSIS: Retrieves the data for a specified setting index
  725. from a user's clone (initial state) if one exists.
  726. NOTES: returns TRUE if successful, FALSE if no clone exists
  727. ********************************************************************/
  728. BOOL GetCloneData(HGLOBAL hClone,UINT uDataIndex,DWORD *pdwData)
  729. {
  730. USERDATA * pUserDataClone;
  731. if (!hClone) return FALSE;
  732. pUserDataClone = (USERDATA *) GlobalLock(hClone);
  733. if (!pUserDataClone) return FALSE;
  734. *pdwData = pUserDataClone->SettingData[uDataIndex].uData;
  735. GlobalUnlock(hClone);
  736. return TRUE;
  737. }
  738. /*******************************************************************
  739. NAME: DeleteSettings
  740. SYNOPSIS: Deletes all settings for a policy; called if the policy
  741. is turned off
  742. NOTES: In direct-registry mode, deletes the value(s). When
  743. operating on a policy file, marks the values to be deleted.
  744. DeleteSettings calls worker function DeleteSetting so
  745. that hierarchy of key names works correctly (pszCurrentKeyName
  746. is preserved in DeleteSettings, but individual settings
  747. may override it in DeleteSetting)
  748. ********************************************************************/
  749. UINT DeleteSettings(USERDATA * pUserData,TABLEENTRY * pTableEntry,HKEY hkeyRoot,
  750. CHAR * pszCurrentKeyName)
  751. {
  752. UINT uRet=ERROR_SUCCESS;
  753. UINT DeleteSetting(USERDATA * pUserData,TABLEENTRY * pTableEntry,HKEY hkeyRoot,
  754. CHAR * pszCurrentKeyName);
  755. while (pTableEntry && (uRet == ERROR_SUCCESS)) {
  756. uRet = DeleteSetting(pUserData,pTableEntry,hkeyRoot,pszCurrentKeyName);
  757. pTableEntry = pTableEntry->pNext;
  758. }
  759. return uRet;
  760. }
  761. UINT DeleteSetting(USERDATA * pUserData,TABLEENTRY * pTableEntry,HKEY hkeyRoot,
  762. CHAR * pszCurrentKeyName)
  763. {
  764. CHAR * pszValueName=NULL;
  765. DWORD dwSettingType;
  766. UINT uRet;
  767. // if this setting has its own key name, use it to override parent's key name
  768. if (pTableEntry->uOffsetKeyName) {
  769. pszCurrentKeyName = GETKEYNAMEPTR(pTableEntry);
  770. }
  771. dwSettingType = pTableEntry->dwType & STYPE_MASK;
  772. // special handling for listboxes, drop-down listboxes and static text
  773. // controls
  774. switch (dwSettingType) {
  775. case STYPE_LISTBOX:
  776. // for listboxes, call SaveListboxData to delete (fErase param set to TRUE)
  777. return SaveListboxData(pUserData,pTableEntry,hkeyRoot,pszCurrentKeyName,
  778. TRUE,TRUE);
  779. break;
  780. case STYPE_DROPDOWNLIST:
  781. {
  782. DWORD dwData;
  783. dwData = pUserData->SettingData[((SETTINGS *)
  784. pTableEntry)->uDataIndex].uData;
  785. // no data set, nothing to do
  786. if (dwData == NO_DATA_INDEX)
  787. break;
  788. if (((SETTINGS *) pTableEntry)->uOffsetValueName) {
  789. pszValueName = GETVALUENAMEPTR(((SETTINGS *) pTableEntry));
  790. } else {
  791. return ERROR_NOT_ENOUGH_MEMORY; // should never happen, but bag out just in case
  792. }
  793. // erase the dropdown value (and any associated action lists)
  794. uRet = WriteDropdownValue(pTableEntry,hkeyRoot,pszCurrentKeyName,
  795. pszValueName,dwData,TRUE);
  796. if (uRet != ERROR_SUCCESS)
  797. return uRet;
  798. // fall through and do processing below
  799. }
  800. break;
  801. case STYPE_TEXT:
  802. return ERROR_SUCCESS; // static text w/no reg value, nothing to do
  803. break;
  804. }
  805. // otherwise delete the value
  806. if (((SETTINGS *) pTableEntry)->uOffsetValueName) {
  807. pszValueName = GETVALUENAMEPTR(((SETTINGS *) pTableEntry));
  808. } else {
  809. return ERROR_NOT_ENOUGH_MEMORY; // should never happen, but bag out just in case
  810. }
  811. // delete the value
  812. DeleteRegistryValue(hkeyRoot,pszCurrentKeyName,pszValueName);
  813. if ((dwAppState & AS_POLICYFILE) && !(dwCmdLineFlags & CLF_DIALOGMODE)) {
  814. // if writing to a policy file, also mark it as deleted.
  815. // WriteCustomValue_W will prepend "**del." to the value name
  816. WriteCustomValue_W(hkeyRoot,pszCurrentKeyName,pszValueName,NULL,0,
  817. VF_DELETE | ((SETTINGS *) pTableEntry)->dwFlags,FALSE);
  818. }
  819. return ERROR_SUCCESS;
  820. }
  821. UINT SaveListboxData(USERDATA * pUserData,TABLEENTRY * pTableEntry,HKEY hkeyRoot,
  822. CHAR * pszCurrentKeyName,BOOL fErase,BOOL fMarkDeleted)
  823. {
  824. UINT uOffset,uRet,nItem=1;
  825. HKEY hKey;
  826. CHAR * pszData,* pszName;
  827. CHAR szValueName[MAX_PATH+1];
  828. DWORD cbValueName;
  829. LISTBOXINFO * pListboxInfo = (LISTBOXINFO *)
  830. GETOBJECTDATAPTR(((SETTINGS *) pTableEntry));
  831. if ((uRet=RegCreateKey(hkeyRoot,pszCurrentKeyName,&hKey)) != ERROR_SUCCESS)
  832. return uRet;
  833. uOffset = pUserData->SettingData[((SETTINGS *)
  834. pTableEntry)->uDataIndex].uOffsetData;
  835. // erase all values for this key, first off
  836. while (TRUE) {
  837. cbValueName=sizeof(szValueName);
  838. uRet=RegEnumValue(hKey,0,szValueName,&cbValueName,NULL,
  839. NULL,NULL,NULL);
  840. // stop if we're out of items
  841. if (uRet != ERROR_SUCCESS && uRet != ERROR_MORE_DATA)
  842. break;
  843. RegDeleteValue(hKey,szValueName);
  844. }
  845. uRet=ERROR_SUCCESS;
  846. if (!fErase || fMarkDeleted) {
  847. // if in policy file mode, write a control code that will cause
  848. // all values under that key to be deleted when client downloads from the file.
  849. // Don't do this if listbox is additive (DF_ADDITIVE), in that case whatever
  850. // we write here will be dumped in along with existing values
  851. if ((dwAppState & AS_POLICYFILE) && !(dwCmdLineFlags & CLF_DIALOGMODE) &&
  852. !(((SETTINGS *) pTableEntry)->dwFlags & DF_ADDITIVE))
  853. uRet=WriteRegistryStringValue(hkeyRoot,pszCurrentKeyName,(CHAR *) szDELVALS,
  854. (CHAR *) szNOVALUE, FALSE);
  855. }
  856. if (!fErase) {
  857. if (uOffset) {
  858. pszData = ((STRDATA *) ((CHAR *) pUserData + uOffset))->szData;
  859. while (*pszData && (uRet == ERROR_SUCCESS)) {
  860. UINT nLen = lstrlen(pszData)+1;
  861. if (((SETTINGS *)pTableEntry)->dwFlags & DF_EXPLICITVALNAME) {
  862. // value name specified for each item
  863. pszName = pszData; // value name
  864. pszData += nLen; // now pszData points to value data
  865. nLen = lstrlen(pszData)+1;
  866. } else {
  867. // value name is either same as the data, or a prefix
  868. // with a number
  869. if (!pListboxInfo->uOffsetPrefix) {
  870. // if no prefix set, then name = data
  871. pszName = pszData;
  872. } else {
  873. // value name is "<prefix><n>" where n=1,2,etc.
  874. wsprintf(szValueName,"%s%lu",(CHAR *) pTableEntry +
  875. pListboxInfo->uOffsetPrefix,nItem);
  876. pszName = szValueName;
  877. nItem++;
  878. }
  879. }
  880. uRet=RegSetValueEx(hKey,pszName,0,REG_SZ,pszData,
  881. nLen);
  882. pszData += nLen;
  883. }
  884. }
  885. }
  886. RegCloseKey(hKey);
  887. return uRet;
  888. }