{"id":15092,"date":"2021-12-17T16:02:59","date_gmt":"2021-12-17T16:02:59","guid":{"rendered":"https:\/\/lgildv5i97.onrocket.site\/answers\/?post_type=question&#038;p=15092"},"modified":"2021-12-17T16:03:20","modified_gmt":"2021-12-17T16:03:20","slug":"solved-batch-file-to-set-variable-registry-keys-as-variables","status":"publish","type":"question","link":"https:\/\/computing.net\/answers\/programming\/batch-file-to-set-variable-registry-keys-as-variables\/28873.html","title":{"rendered":"Solved Batch File To Set Variable Registry Keys As Variables"},"content":{"rendered":"<p>Part of the maintenance we do at my work involves rebuilding user&#8217;s profiles and in windows 7 the registry key for the old profile needs to be deleted before the new profile will work correctly.<\/p>\n<p>The problem I&#8217;m running into is that in order to get the correct key to delete I need to run a query on the user&#8217;s profile ID (the ID is not part of the actual key) but when either exporting to a text file or using a FOR command only the very last part of the result is being returned.<\/p>\n<p>So when I run:<\/p>\n<p>reg query &#8220;HKLM\\SOFTWARE\\WOW6432NODE\\MICROSOFT\\WINDOWS NT\\CURRENTVERSION\\PROFILELIST&#8221; \/s \/f %curuser%&gt;profilerebuild.txt<\/p>\n<p>setlocal enabledelayedexpansion<br \/>\nset rukey=<br \/>\nFOR \/F &#8220;tokens=1,2 delims= &#8221; %%A IN (profilerebuild.txt) DO set rukey=%%A<\/p>\n<p>Echo Your current registry profile path is: %rukey%<\/p>\n<p>(where %curuser% is set earlier in the batch file) what I get returned as %rukey% is &#8220;End of search: 1 match(es) found.&#8221; rather than the key.<\/p>\n<p>The confusing part is that when I have the FOR command ending with &#8220;&#8230;DO ECHO %%A&#8221; instead of &#8220;DO SET rukey=%%A&#8221; it echo&#8217;s and displays the key.<\/p>\n<p>Is there something that I&#8217;m overlooking with this?<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"inline_featured_image":false,"iawp_total_views":35},"question-category":[55],"question_tags":[],"class_list":["post-15092","question","type-question","status-publish","hentry","question-category-programming"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question\/15092","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question"}],"about":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/types\/question"}],"author":[{"embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/comments?post=15092"}],"wp:attachment":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/media?parent=15092"}],"wp:term":[{"taxonomy":"question-category","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question-category?post=15092"},{"taxonomy":"question_tags","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question_tags?post=15092"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}