{"id":94815,"date":"2016-11-28T07:00:00","date_gmt":"2016-11-28T22:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/?p=94815"},"modified":"2019-03-13T10:34:17","modified_gmt":"2019-03-13T17:34:17","slug":"20161128-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20161128-00\/?p=94815","title":{"rendered":"If I simply want to create a registry key but don&#8217;t intend to do anything else with it, what security access mask should I ask for?"},"content":{"rendered":"<p>A customer wanted to create a registry key if it didn&#8217;t already exist, but they weren&#8217;t interested in writing anything to the key yet. They just wanted to ensure that it existed. Now, we know that the <code>Reg&shy;Create&shy;Key&shy;Ex<\/code> function will either open a key (if it exists) or create a key (if it doesn&#8217;t already exist). That seems to fit the bill perfectly, so we have this so far: <\/p>\n<pre>\nHKEY subKey;\nLONG result = RegCreateKeyEx(\n    parentKey, subkeyName, 0, nullptr,\n    0, ????, nullptr, &amp;subKey, nullptr);\nif (result == ERROR_SUCCESS) {\n    RegCloseKey(subKey);\n}\n<\/pre>\n<p>Now, we know that the <code>parentKey<\/code> must have been opened with <code>KEY_CREATE_SUB_KEY<\/code> access in order for us to be able to create a subkey. But what goes into the question marks, which specify the access mask for the subkey? Should we say <code>KEY_WRITE<\/code> because we are creating the key? Or do we say <code>0<\/code> because we aren&#8217;t intending to do anything at all with the new key? <\/p>\n<p>In this case, saying <code>0<\/code> is just fine. The program doesn&#8217;t do anything with the subkey aside from close the handle, and closing a handle doesn&#8217;t require any special permissions. If you planned to use the <code>subKey<\/code> to perform any operations on the subkey, then you need to request an access mask that is compatible with the operations you intend to perform. <\/p>\n<p>But if you don&#8217;t intend to perform any operations, then you don&#8217;t need to request any access. Passing <code>0<\/code> is just fine. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you need nothing, then ask for nothing.<\/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-94815","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>If you need nothing, then ask for nothing.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/94815","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=94815"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/94815\/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=94815"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=94815"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=94815"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}