2 * winstore.c: Windows-specific implementation of the interface
\r
3 * defined in storage.h.
\r
10 #include "storage.h"
\r
13 #ifndef CSIDL_APPDATA
\r
14 #define CSIDL_APPDATA 0x001a
\r
16 #ifndef CSIDL_LOCAL_APPDATA
\r
17 #define CSIDL_LOCAL_APPDATA 0x001c
\r
20 static const char *const reg_jumplist_key = PUTTY_REG_POS "\\Jumplist";
\r
21 static const char *const reg_jumplist_value = "Recent sessions";
\r
22 static const char *const puttystr = PUTTY_REG_POS "\\Sessions";
\r
24 static const char hex[16] = "0123456789ABCDEF";
\r
26 static int tried_shgetfolderpath = FALSE;
\r
27 static HMODULE shell32_module = NULL;
\r
28 DECL_WINDOWS_FUNCTION(static, HRESULT, SHGetFolderPathA,
\r
29 (HWND, int, HANDLE, DWORD, LPSTR));
\r
31 static void mungestr(const char *in, char *out)
\r
36 if (*in == ' ' || *in == '\\' || *in == '*' || *in == '?' ||
\r
37 *in == '%' || *in < ' ' || *in > '~' || (*in == '.'
\r
40 *out++ = hex[((unsigned char) *in) >> 4];
\r
41 *out++ = hex[((unsigned char) *in) & 15];
\r
51 static void unmungestr(const char *in, char *out, int outlen)
\r
54 if (*in == '%' && in[1] && in[2]) {
\r
58 i -= (i > 9 ? 7 : 0);
\r
60 j -= (j > 9 ? 7 : 0);
\r
62 *out++ = (i << 4) + j;
\r
76 void *open_settings_w(const char *sessionname, char **errmsg)
\r
78 HKEY subkey1, sesskey;
\r
84 if (!sessionname || !*sessionname)
\r
85 sessionname = "Default Settings";
\r
87 p = snewn(3 * strlen(sessionname) + 1, char);
\r
88 mungestr(sessionname, p);
\r
90 ret = RegCreateKey(HKEY_CURRENT_USER, puttystr, &subkey1);
\r
91 if (ret != ERROR_SUCCESS) {
\r
93 *errmsg = dupprintf("Unable to create registry key\n"
\r
94 "HKEY_CURRENT_USER\\%s", puttystr);
\r
97 ret = RegCreateKey(subkey1, p, &sesskey);
\r
98 RegCloseKey(subkey1);
\r
99 if (ret != ERROR_SUCCESS) {
\r
100 *errmsg = dupprintf("Unable to create registry key\n"
\r
101 "HKEY_CURRENT_USER\\%s\\%s", puttystr, p);
\r
106 return (void *) sesskey;
\r
109 void write_setting_s(void *handle, const char *key, const char *value)
\r
112 RegSetValueEx((HKEY) handle, key, 0, REG_SZ, value,
\r
113 1 + strlen(value));
\r
116 void write_setting_i(void *handle, const char *key, int value)
\r
119 RegSetValueEx((HKEY) handle, key, 0, REG_DWORD,
\r
120 (CONST BYTE *) &value, sizeof(value));
\r
123 void close_settings_w(void *handle)
\r
125 RegCloseKey((HKEY) handle);
\r
128 void *open_settings_r(const char *sessionname)
\r
130 HKEY subkey1, sesskey;
\r
133 if (!sessionname || !*sessionname)
\r
134 sessionname = "Default Settings";
\r
136 p = snewn(3 * strlen(sessionname) + 1, char);
\r
137 mungestr(sessionname, p);
\r
139 if (RegOpenKey(HKEY_CURRENT_USER, puttystr, &subkey1) != ERROR_SUCCESS) {
\r
142 if (RegOpenKey(subkey1, p, &sesskey) != ERROR_SUCCESS) {
\r
145 RegCloseKey(subkey1);
\r
150 return (void *) sesskey;
\r
153 char *read_setting_s(void *handle, const char *key, char *buffer, int buflen)
\r
159 RegQueryValueEx((HKEY) handle, key, 0,
\r
160 &type, buffer, &size) != ERROR_SUCCESS ||
\r
161 type != REG_SZ) return NULL;
\r
166 int read_setting_i(void *handle, const char *key, int defvalue)
\r
168 DWORD type, val, size;
\r
169 size = sizeof(val);
\r
172 RegQueryValueEx((HKEY) handle, key, 0, &type,
\r
173 (BYTE *) &val, &size) != ERROR_SUCCESS ||
\r
174 size != sizeof(val) || type != REG_DWORD)
\r
180 int read_setting_fontspec(void *handle, const char *name, FontSpec *result)
\r
185 if (!read_setting_s(handle, name, ret.name, sizeof(ret.name)))
\r
187 settingname = dupcat(name, "IsBold", NULL);
\r
188 ret.isbold = read_setting_i(handle, settingname, -1);
\r
189 sfree(settingname);
\r
190 if (ret.isbold == -1) return 0;
\r
191 settingname = dupcat(name, "CharSet", NULL);
\r
192 ret.charset = read_setting_i(handle, settingname, -1);
\r
193 sfree(settingname);
\r
194 if (ret.charset == -1) return 0;
\r
195 settingname = dupcat(name, "Height", NULL);
\r
196 ret.height = read_setting_i(handle, settingname, INT_MIN);
\r
197 sfree(settingname);
\r
198 if (ret.height == INT_MIN) return 0;
\r
203 void write_setting_fontspec(void *handle, const char *name, FontSpec font)
\r
207 write_setting_s(handle, name, font.name);
\r
208 settingname = dupcat(name, "IsBold", NULL);
\r
209 write_setting_i(handle, settingname, font.isbold);
\r
210 sfree(settingname);
\r
211 settingname = dupcat(name, "CharSet", NULL);
\r
212 write_setting_i(handle, settingname, font.charset);
\r
213 sfree(settingname);
\r
214 settingname = dupcat(name, "Height", NULL);
\r
215 write_setting_i(handle, settingname, font.height);
\r
216 sfree(settingname);
\r
219 int read_setting_filename(void *handle, const char *name, Filename *result)
\r
221 return !!read_setting_s(handle, name, result->path, sizeof(result->path));
\r
224 void write_setting_filename(void *handle, const char *name, Filename result)
\r
226 write_setting_s(handle, name, result.path);
\r
229 void close_settings_r(void *handle)
\r
231 RegCloseKey((HKEY) handle);
\r
234 void del_settings(const char *sessionname)
\r
239 if (RegOpenKey(HKEY_CURRENT_USER, puttystr, &subkey1) != ERROR_SUCCESS)
\r
242 p = snewn(3 * strlen(sessionname) + 1, char);
\r
243 mungestr(sessionname, p);
\r
244 RegDeleteKey(subkey1, p);
\r
247 RegCloseKey(subkey1);
\r
249 remove_session_from_jumplist(sessionname);
\r
252 struct enumsettings {
\r
257 void *enum_settings_start(void)
\r
259 struct enumsettings *ret;
\r
262 if (RegOpenKey(HKEY_CURRENT_USER, puttystr, &key) != ERROR_SUCCESS)
\r
265 ret = snew(struct enumsettings);
\r
274 char *enum_settings_next(void *handle, char *buffer, int buflen)
\r
276 struct enumsettings *e = (struct enumsettings *) handle;
\r
278 otherbuf = snewn(3 * buflen, char);
\r
279 if (RegEnumKey(e->key, e->i++, otherbuf, 3 * buflen) == ERROR_SUCCESS) {
\r
280 unmungestr(otherbuf, buffer, buflen);
\r
289 void enum_settings_finish(void *handle)
\r
291 struct enumsettings *e = (struct enumsettings *) handle;
\r
292 RegCloseKey(e->key);
\r
296 static void hostkey_regname(char *buffer, const char *hostname,
\r
297 int port, const char *keytype)
\r
300 strcpy(buffer, keytype);
\r
301 strcat(buffer, "@");
\r
302 len = strlen(buffer);
\r
303 len += sprintf(buffer + len, "%d:", port);
\r
304 mungestr(hostname, buffer + strlen(buffer));
\r
307 int verify_host_key(const char *hostname, int port,
\r
308 const char *keytype, const char *key)
\r
310 char *otherstr, *regname;
\r
317 len = 1 + strlen(key);
\r
320 * Now read a saved key in from the registry and see what it
\r
323 otherstr = snewn(len, char);
\r
324 regname = snewn(3 * (strlen(hostname) + strlen(keytype)) + 15, char);
\r
326 hostkey_regname(regname, hostname, port, keytype);
\r
328 if (RegOpenKey(HKEY_CURRENT_USER, PUTTY_REG_POS "\\SshHostKeys",
\r
329 &rkey) != ERROR_SUCCESS)
\r
330 return 1; /* key does not exist in registry */
\r
333 ret = RegQueryValueEx(rkey, regname, NULL, &type, otherstr, &readlen);
\r
335 if (ret != ERROR_SUCCESS && ret != ERROR_MORE_DATA &&
\r
336 !strcmp(keytype, "rsa")) {
\r
338 * Key didn't exist. If the key type is RSA, we'll try
\r
339 * another trick, which is to look up the _old_ key format
\r
340 * under just the hostname and translate that.
\r
342 char *justhost = regname + 1 + strcspn(regname, ":");
\r
343 char *oldstyle = snewn(len + 10, char); /* safety margin */
\r
345 ret = RegQueryValueEx(rkey, justhost, NULL, &type,
\r
346 oldstyle, &readlen);
\r
348 if (ret == ERROR_SUCCESS && type == REG_SZ) {
\r
350 * The old format is two old-style bignums separated by
\r
351 * a slash. An old-style bignum is made of groups of
\r
352 * four hex digits: digits are ordered in sensible
\r
353 * (most to least significant) order within each group,
\r
354 * but groups are ordered in silly (least to most)
\r
355 * order within the bignum. The new format is two
\r
356 * ordinary C-format hex numbers (0xABCDEFG...XYZ, with
\r
357 * A nonzero except in the special case 0x0, which
\r
358 * doesn't appear anyway in RSA keys) separated by a
\r
359 * comma. All hex digits are lowercase in both formats.
\r
361 char *p = otherstr;
\r
362 char *q = oldstyle;
\r
365 for (i = 0; i < 2; i++) {
\r
366 int ndigits, nwords;
\r
369 ndigits = strcspn(q, "/"); /* find / or end of string */
\r
370 nwords = ndigits / 4;
\r
371 /* now trim ndigits to remove leading zeros */
\r
372 while (q[(ndigits - 1) ^ 3] == '0' && ndigits > 1)
\r
374 /* now move digits over to new string */
\r
375 for (j = 0; j < ndigits; j++)
\r
376 p[ndigits - 1 - j] = q[j ^ 3];
\r
380 q++; /* eat the slash */
\r
381 *p++ = ','; /* add a comma */
\r
383 *p = '\0'; /* terminate the string */
\r
387 * Now _if_ this key matches, we'll enter it in the new
\r
388 * format. If not, we'll assume something odd went
\r
389 * wrong, and hyper-cautiously do nothing.
\r
391 if (!strcmp(otherstr, key))
\r
392 RegSetValueEx(rkey, regname, 0, REG_SZ, otherstr,
\r
393 strlen(otherstr) + 1);
\r
399 compare = strcmp(otherstr, key);
\r
404 if (ret == ERROR_MORE_DATA ||
\r
405 (ret == ERROR_SUCCESS && type == REG_SZ && compare))
\r
406 return 2; /* key is different in registry */
\r
407 else if (ret != ERROR_SUCCESS || type != REG_SZ)
\r
408 return 1; /* key does not exist in registry */
\r
410 return 0; /* key matched OK in registry */
\r
413 void store_host_key(const char *hostname, int port,
\r
414 const char *keytype, const char *key)
\r
419 regname = snewn(3 * (strlen(hostname) + strlen(keytype)) + 15, char);
\r
421 hostkey_regname(regname, hostname, port, keytype);
\r
423 if (RegCreateKey(HKEY_CURRENT_USER, PUTTY_REG_POS "\\SshHostKeys",
\r
424 &rkey) == ERROR_SUCCESS) {
\r
425 RegSetValueEx(rkey, regname, 0, REG_SZ, key, strlen(key) + 1);
\r
427 } /* else key does not exist in registry */
\r
433 * Open (or delete) the random seed file.
\r
435 enum { DEL, OPEN_R, OPEN_W };
\r
436 static int try_random_seed(char const *path, int action, HANDLE *ret)
\r
438 if (action == DEL) {
\r
440 *ret = INVALID_HANDLE_VALUE;
\r
441 return FALSE; /* so we'll do the next ones too */
\r
444 *ret = CreateFile(path,
\r
445 action == OPEN_W ? GENERIC_WRITE : GENERIC_READ,
\r
446 action == OPEN_W ? 0 : (FILE_SHARE_READ |
\r
449 action == OPEN_W ? CREATE_ALWAYS : OPEN_EXISTING,
\r
450 action == OPEN_W ? FILE_ATTRIBUTE_NORMAL : 0,
\r
453 return (*ret != INVALID_HANDLE_VALUE);
\r
456 static HANDLE access_random_seed(int action)
\r
461 char seedpath[2 * MAX_PATH + 10] = "\0";
\r
464 * Iterate over a selection of possible random seed paths until
\r
465 * we find one that works.
\r
467 * We do this iteration separately for reading and writing,
\r
468 * meaning that we will automatically migrate random seed files
\r
469 * if a better location becomes available (by reading from the
\r
470 * best location in which we actually find one, and then
\r
471 * writing to the best location in which we can _create_ one).
\r
475 * First, try the location specified by the user in the
\r
476 * Registry, if any.
\r
478 size = sizeof(seedpath);
\r
479 if (RegOpenKey(HKEY_CURRENT_USER, PUTTY_REG_POS, &rkey) ==
\r
481 int ret = RegQueryValueEx(rkey, "RandSeedFile",
\r
482 0, &type, seedpath, &size);
\r
483 if (ret != ERROR_SUCCESS || type != REG_SZ)
\r
484 seedpath[0] = '\0';
\r
487 if (*seedpath && try_random_seed(seedpath, action, &rethandle))
\r
492 * Next, try the user's local Application Data directory,
\r
493 * followed by their non-local one. This is found using the
\r
494 * SHGetFolderPath function, which won't be present on all
\r
495 * versions of Windows.
\r
497 if (!tried_shgetfolderpath) {
\r
498 /* This is likely only to bear fruit on systems with IE5+
\r
499 * installed, or WinMe/2K+. There is some faffing with
\r
500 * SHFOLDER.DLL we could do to try to find an equivalent
\r
501 * on older versions of Windows if we cared enough.
\r
502 * However, the invocation below requires IE5+ anyway,
\r
503 * so stuff that. */
\r
504 shell32_module = load_system32_dll("shell32.dll");
\r
505 GET_WINDOWS_FUNCTION(shell32_module, SHGetFolderPathA);
\r
506 tried_shgetfolderpath = TRUE;
\r
508 if (p_SHGetFolderPathA) {
\r
509 if (SUCCEEDED(p_SHGetFolderPathA(NULL, CSIDL_LOCAL_APPDATA,
\r
510 NULL, SHGFP_TYPE_CURRENT, seedpath))) {
\r
511 strcat(seedpath, "\\PUTTY.RND");
\r
512 if (try_random_seed(seedpath, action, &rethandle))
\r
516 if (SUCCEEDED(p_SHGetFolderPathA(NULL, CSIDL_APPDATA,
\r
517 NULL, SHGFP_TYPE_CURRENT, seedpath))) {
\r
518 strcat(seedpath, "\\PUTTY.RND");
\r
519 if (try_random_seed(seedpath, action, &rethandle))
\r
525 * Failing that, try %HOMEDRIVE%%HOMEPATH% as a guess at the
\r
526 * user's home directory.
\r
532 GetEnvironmentVariable("HOMEDRIVE", seedpath,
\r
535 GetEnvironmentVariable("HOMEPATH", seedpath + len,
\r
536 sizeof(seedpath) - len);
\r
538 strcat(seedpath, "\\PUTTY.RND");
\r
539 if (try_random_seed(seedpath, action, &rethandle))
\r
545 * And finally, fall back to C:\WINDOWS.
\r
547 GetWindowsDirectory(seedpath, sizeof(seedpath));
\r
548 strcat(seedpath, "\\PUTTY.RND");
\r
549 if (try_random_seed(seedpath, action, &rethandle))
\r
553 * If even that failed, give up.
\r
555 return INVALID_HANDLE_VALUE;
\r
558 void read_random_seed(noise_consumer_t consumer)
\r
560 HANDLE seedf = access_random_seed(OPEN_R);
\r
562 if (seedf != INVALID_HANDLE_VALUE) {
\r
567 if (ReadFile(seedf, buf, sizeof(buf), &len, NULL) && len)
\r
568 consumer(buf, len);
\r
572 CloseHandle(seedf);
\r
576 void write_random_seed(void *data, int len)
\r
578 HANDLE seedf = access_random_seed(OPEN_W);
\r
580 if (seedf != INVALID_HANDLE_VALUE) {
\r
583 WriteFile(seedf, data, len, &lenwritten, NULL);
\r
584 CloseHandle(seedf);
\r
589 * Internal function supporting the jump list registry code. All the
\r
590 * functions to add, remove and read the list have substantially
\r
591 * similar content, so this is a generalisation of all of them which
\r
592 * transforms the list in the registry by prepending 'add' (if
\r
593 * non-null), removing 'rem' from what's left (if non-null), and
\r
594 * returning the resulting concatenated list of strings in 'out' (if
\r
597 static int transform_jumplist_registry
\r
598 (const char *add, const char *rem, char **out)
\r
601 HKEY pjumplist_key, psettings_tmp;
\r
604 char *old_value, *new_value;
\r
605 char *piterator_old, *piterator_new, *piterator_tmp;
\r
607 ret = RegCreateKeyEx(HKEY_CURRENT_USER, reg_jumplist_key, 0, NULL,
\r
608 REG_OPTION_NON_VOLATILE, (KEY_READ | KEY_WRITE), NULL,
\r
609 &pjumplist_key, NULL);
\r
610 if (ret != ERROR_SUCCESS) {
\r
611 return JUMPLISTREG_ERROR_KEYOPENCREATE_FAILURE;
\r
614 /* Get current list of saved sessions in the registry. */
\r
615 value_length = 200;
\r
616 old_value = snewn(value_length, char);
\r
617 ret = RegQueryValueEx(pjumplist_key, reg_jumplist_value, NULL, &type,
\r
618 old_value, &value_length);
\r
619 /* When the passed buffer is too small, ERROR_MORE_DATA is
\r
620 * returned and the required size is returned in the length
\r
622 if (ret == ERROR_MORE_DATA) {
\r
624 old_value = snewn(value_length, char);
\r
625 ret = RegQueryValueEx(pjumplist_key, reg_jumplist_value, NULL, &type,
\r
626 old_value, &value_length);
\r
629 if (ret == ERROR_FILE_NOT_FOUND) {
\r
630 /* Value doesn't exist yet. Start from an empty value. */
\r
632 *(old_value + 1) = '\0';
\r
633 } else if (ret != ERROR_SUCCESS) {
\r
634 /* Some non-recoverable error occurred. */
\r
636 RegCloseKey(pjumplist_key);
\r
637 return JUMPLISTREG_ERROR_VALUEREAD_FAILURE;
\r
638 } else if (type != REG_MULTI_SZ) {
\r
639 /* The value present in the registry has the wrong type: we
\r
640 * try to delete it and start from an empty value. */
\r
641 ret = RegDeleteValue(pjumplist_key, reg_jumplist_value);
\r
642 if (ret != ERROR_SUCCESS) {
\r
644 RegCloseKey(pjumplist_key);
\r
645 return JUMPLISTREG_ERROR_VALUEREAD_FAILURE;
\r
649 *(old_value + 1) = '\0';
\r
652 /* Check validity of registry data: REG_MULTI_SZ value must end
\r
654 piterator_tmp = old_value;
\r
655 while (((piterator_tmp - old_value) < (value_length - 1)) &&
\r
656 !(*piterator_tmp == '\0' && *(piterator_tmp+1) == '\0')) {
\r
660 if ((piterator_tmp - old_value) >= (value_length-1)) {
\r
661 /* Invalid value. Start from an empty value. */
\r
663 *(old_value + 1) = '\0';
\r
667 * Modify the list, if we're modifying.
\r
670 /* Walk through the existing list and construct the new list of
\r
671 * saved sessions. */
\r
672 new_value = snewn(value_length + (add ? strlen(add) + 1 : 0), char);
\r
673 piterator_new = new_value;
\r
674 piterator_old = old_value;
\r
676 /* First add the new item to the beginning of the list. */
\r
678 strcpy(piterator_new, add);
\r
679 piterator_new += strlen(piterator_new) + 1;
\r
681 /* Now add the existing list, taking care to leave out the removed
\r
682 * item, if it was already in the existing list. */
\r
683 while (*piterator_old != '\0') {
\r
684 if (!rem || strcmp(piterator_old, rem) != 0) {
\r
685 /* Check if this is a valid session, otherwise don't add. */
\r
686 psettings_tmp = open_settings_r(piterator_old);
\r
687 if (psettings_tmp != NULL) {
\r
688 close_settings_r(psettings_tmp);
\r
689 strcpy(piterator_new, piterator_old);
\r
690 piterator_new += strlen(piterator_new) + 1;
\r
693 piterator_old += strlen(piterator_old) + 1;
\r
695 *piterator_new = '\0';
\r
698 /* Save the new list to the registry. */
\r
699 ret = RegSetValueEx(pjumplist_key, reg_jumplist_value, 0, REG_MULTI_SZ,
\r
700 new_value, piterator_new - new_value);
\r
703 old_value = new_value;
\r
705 ret = ERROR_SUCCESS;
\r
708 * Either return or free the result.
\r
715 /* Clean up and return. */
\r
716 RegCloseKey(pjumplist_key);
\r
718 if (ret != ERROR_SUCCESS) {
\r
719 return JUMPLISTREG_ERROR_VALUEWRITE_FAILURE;
\r
721 return JUMPLISTREG_OK;
\r
725 /* Adds a new entry to the jumplist entries in the registry. */
\r
726 int add_to_jumplist_registry(const char *item)
\r
728 return transform_jumplist_registry(item, item, NULL);
\r
731 /* Removes an item from the jumplist entries in the registry. */
\r
732 int remove_from_jumplist_registry(const char *item)
\r
734 return transform_jumplist_registry(NULL, item, NULL);
\r
737 /* Returns the jumplist entries from the registry. Caller must free
\r
738 * the returned pointer. */
\r
739 char *get_jumplist_registry_entries (void)
\r
743 if (transform_jumplist_registry(NULL,NULL,&list_value) != ERROR_SUCCESS) {
\r
744 list_value = snewn(2, char);
\r
745 *list_value = '\0';
\r
746 *(list_value + 1) = '\0';
\r
752 * Recursively delete a registry key and everything under it.
\r
754 static void registry_recursive_remove(HKEY key)
\r
757 char name[MAX_PATH + 1];
\r
761 while (RegEnumKey(key, i, name, sizeof(name)) == ERROR_SUCCESS) {
\r
762 if (RegOpenKey(key, name, &subkey) == ERROR_SUCCESS) {
\r
763 registry_recursive_remove(subkey);
\r
764 RegCloseKey(subkey);
\r
766 RegDeleteKey(key, name);
\r
770 void cleanup_all(void)
\r
774 char name[MAX_PATH + 1];
\r
776 /* ------------------------------------------------------------
\r
777 * Wipe out the random seed file, in all of its possible
\r
780 access_random_seed(DEL);
\r
782 /* ------------------------------------------------------------
\r
783 * Ask Windows to delete any jump list information associated
\r
784 * with this installation of PuTTY.
\r
788 /* ------------------------------------------------------------
\r
789 * Destroy all registry information associated with PuTTY.
\r
793 * Open the main PuTTY registry key and remove everything in it.
\r
795 if (RegOpenKey(HKEY_CURRENT_USER, PUTTY_REG_POS, &key) ==
\r
797 registry_recursive_remove(key);
\r
801 * Now open the parent key and remove the PuTTY main key. Once
\r
802 * we've done that, see if the parent key has any other
\r
805 if (RegOpenKey(HKEY_CURRENT_USER, PUTTY_REG_PARENT,
\r
806 &key) == ERROR_SUCCESS) {
\r
807 RegDeleteKey(key, PUTTY_REG_PARENT_CHILD);
\r
808 ret = RegEnumKey(key, 0, name, sizeof(name));
\r
811 * If the parent key had no other children, we must delete
\r
812 * it in its turn. That means opening the _grandparent_
\r
815 if (ret != ERROR_SUCCESS) {
\r
816 if (RegOpenKey(HKEY_CURRENT_USER, PUTTY_REG_GPARENT,
\r
817 &key) == ERROR_SUCCESS) {
\r
818 RegDeleteKey(key, PUTTY_REG_GPARENT_CHILD);
\r