{"id":110160,"date":"2024-08-21T07:59:46","date_gmt":"2024-08-21T14:59:46","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=110160"},"modified":"2024-08-21T07:59:46","modified_gmt":"2024-08-21T14:59:46","slug":"20240821-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20240821-46\/?p=110160","title":{"rendered":"What does <CODE>ERROR_<WBR>KEY_<WBR>DELETED<\/CODE> mean?"},"content":{"rendered":"<p>A customer discovered through telemetry that their program was failing with the error code <code>ERROR_<wbr \/>KEY_<wbr \/>DELETED<\/code> when they try to set a value in the registry. What does this error mean?<\/p>\n<p>When you open a registry key, you get a handle, and that handle refers to the key you opened. If somebody deletes that registry key, your handle remains a valid handle, but all operations on it fail with <code>ERROR_<wbr \/>KEY_<wbr \/>DELETED<\/code>. The only thing you can do with the handle is close it.<\/p>\n<p>The registry allows a key to be deleted despite there being open handles to it because <a title=\"The inability to lock someone out of the registry is a feature, not a bug\" href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20090326-00\/?p=18703\"> the inability to lock someone out of the registry is a feature, not a bug<\/a>. The deletion succeeds, and all existing handles are now told, &#8220;Sorry, that key no longer exists.&#8221;<\/p>\n<p>Note that if somebody creates a new key with the same name as the deleted key, that does not revive the deleted key. The new key is a different key that just happens to have the same name as the deleted yet. It&#8217;s not the same key. (It shouldn&#8217;t be considered the same key because the security descriptor on the new key may not be the same as the security descriptor on the old key.)<\/p>\n<p>In the customer&#8217;s case, the program opened the registry key when the program started and kept it open until the program ended. There is no code in the program to delete the key, so my guess is that what happened is that the user opened regedit and manually deleted the key, perhaps in a well-intentioned but misguided attempt to reset all settings to their defaults.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You now have a handle to a key that doesn&#8217;t exist, and there&#8217;s nothing you can do with it.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-110160","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>You now have a handle to a key that doesn&#8217;t exist, and there&#8217;s nothing you can do with it.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/110160","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=110160"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/110160\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=110160"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=110160"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=110160"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}