c++ - How to delete botched symbolic links in the registry -
i'm prototyping edits registry create symbolic link 1 area another. i've used following code:
hkey hkfs; hkey hksoftware; dword dwdisposition; lstatus result; result = regopenkeyex(hkey_local_machine, _t("software"), 0, key_create_sub_key , &hksoftware); if (result == 0) { result = regopenkeyex(hksoftware, _t("mykey"), reg_option_open_link, key_write | key_create_link | key_wow64_64key, &hkfs); if (result != error_success) { _tprintf(_t("%d\n"), result); result = regcreatekeyex(hksoftware, _t("mykey"), 0, null, reg_option_create_link, key_write | key_create_link | key_wow64_64key, null, &hkfs, &dwdisposition); _tprintf(_t("%d\n"), result); } if (result == error_success) { //result = zwdeletekey(hkfs); tchar target[] = _t("hkey_local_machine\\software\\wow6432node\\mykey"); result = regsetvalueex(hkfs, _t("symboliclinkvalue"), 0, reg_sz, (const byte const *)target, sizeof(target)); if (result != error_success) { tchar msg[256]; formatmessage(format_message_from_system, null, result, 0, msg, sizeof(msg) / sizeof(tchar), null); _tprintf(_t("failed write symboliclinkvalue: %s"), msg); } regclosekey(hkfs); } else { tchar msg[256]; formatmessage(format_message_from_system, null, result, 0, msg, sizeof(msg) / sizeof(tchar), null); _putts(msg); } } else { tchar msg[256]; formatmessage(format_message_from_system, null, result, 0, msg, sizeof(msg) / sizeof(tchar), null); _tprintf(_t("error opening software: %s"), msg); } regclosekey(hksoftware);
and have 2 problems.
- i cannot delete mykey values have been created under software.
- i access denied errors when attempting write symboliclinkvalue mykey, when running administrator.
i need cleaning registry , making code work.
i found code @ http://www.codeproject.com/articles/11973/registry-symbolic-links solved problems.
this code uses delete registry key representing symbolic link:
typedef long ntstatus; #if !defined(_ntsystem_) #define ntsysapi declspec_import #else #define ntsysapi #endif ntsysapi ntstatus ntapi zwdeletekey( in handle keyhandle ); typedef ntsysapi ntstatus (ntapi *zw_delete_key_proto)(handle); static long dynzwdeletekey(hkey hkey) { long lstatus = error_success; hmodule hntdll = loadlibraryw( l"ntdll.dll" ); if (hntdll) { zw_delete_key_proto lpfnzwdeletekey = (zw_delete_key_proto)getprocaddress(hntdll, "zwdeletekey"); if (lpfnzwdeletekey) lstatus = lpfnzwdeletekey(hkey); else lstatus = getlasterror(); verify(freelibrary(hntdll)); } else lstatus = getlasterror(); return lstatus; }
and code above had couple problems in creating link. these corrected lines make work:
result = regcreatekeyex(hksoftware, _t("mykey"), 0, null, reg_option_create_link, key_all_access | key_create_link | key_wow64_64key, null, &hkfs, &dwdisposition);
...
result = regsetvalueexw(hkfs, l"symboliclinkvalue", 0, reg_link, (const byte const *)target, lstrlen(target) * sizeof(wchar));
Comments
Post a Comment