{"id":14035,"date":"2021-12-14T06:30:27","date_gmt":"2021-12-14T06:30:27","guid":{"rendered":"https:\/\/lgildv5i97.onrocket.site\/answers\/?post_type=question&#038;p=14035"},"modified":"2021-12-14T06:31:53","modified_gmt":"2021-12-14T06:31:53","slug":"solved-batch-file-request-admin","status":"publish","type":"question","link":"https:\/\/computing.net\/answers\/programming\/batch-file-request-admin\/29062.html","title":{"rendered":"Solved Batch File Request Admin"},"content":{"rendered":"<p>I have a batch file that requires administrative privileges to perform most of its task for which it has this bit of code to do that.<\/p>\n<p>&gt;nul 2&gt;&amp;1 &#8220;%SYSTEMROOT%\\system32\\cacls.exe&#8221; &#8220;%SYSTEMROOT%\\system32\\config\\system&#8221;<br \/>\nif &#8216;%errorlevel%&#8217; NEQ &#8216;0&#8217; (<br \/>\necho Requesting administrative privileges&#8230;<br \/>\ngoto UACPrompt<br \/>\n) else ( goto gotAdmin )<br \/>\n:UACPrompt<br \/>\necho Set UAC = CreateObject^(&#8220;Shell.Application&#8221;^) &gt; &#8220;%temp%\\getadmin.vbs&#8221;<br \/>\nset params = %*:&#8221;=&#8221;&#8221;<br \/>\necho UAC.ShellExecute &#8220;%~s0&#8221;, &#8220;%params%&#8221;, &#8220;&#8221;, &#8220;runas&#8221;, 1 &gt;&gt; &#8220;%temp%\\getadmin.vbs&#8221;<br \/>\n&#8220;%temp%\\getadmin.vbs&#8221;<br \/>\nexit \/B<br \/>\n:gotAdmin<br \/>\nif exist &#8220;%temp%\\getadmin.vbs&#8221; ( del &#8220;%temp%\\getadmin.vbs&#8221; )<br \/>\npushd &#8220;%CD%&#8221;<br \/>\nCD \/D &#8220;%~dp0&#8221;<\/p>\n<p>The above code is put in the top of out batch file.<br \/>\nWhen it runs it request Admin and performs its task.<br \/>\nOnly problem is that it opens up another command prompt with out batch in it and closes the one I opened to get it to open the other one.<\/p>\n<p>What we would like is the batch file to open, ask for admin, then continue to run in the same cmd window. If that is possible.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"inline_featured_image":false,"iawp_total_views":1},"question-category":[55],"question_tags":[],"class_list":["post-14035","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\/14035","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=14035"}],"wp:attachment":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/media?parent=14035"}],"wp:term":[{"taxonomy":"question-category","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question-category?post=14035"},{"taxonomy":"question_tags","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question_tags?post=14035"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}