{"id":1512,"date":"2007-04-06T18:39:29","date_gmt":"2007-04-06T13:09:29","guid":{"rendered":"http:\/\/198.58.113.91\/blog\/?p=1512"},"modified":"2019-04-22T17:35:04","modified_gmt":"2019-04-22T17:35:04","slug":"vbscripts-and-uac-elevation","status":"publish","type":"post","link":"https:\/\/www.winhelponline.com\/blog\/vbscripts-and-uac-elevation\/","title":{"rendered":"How to Launch a Vbscript in Elevated Mode (Run as Administrator)"},"content":{"rendered":"<p>With the introduction of User Account Control (UAC) in Windows Vista, you usually open an <a href=\"https:\/\/www.winhelponline.com\/blog\/open-elevated-command-prompt-windows\/\">elevated Command Prompt<\/a> in order to run batch files and scripts that need administrative privileges. Applications can make use of manifest files (using the <em>RequireAdministrator<\/em> flag) to automatically run elevated.<\/p>\n<p>For scripts, this article provides you some neat little tricks using which you can automatically elevate using the ShellExecute &#8220;runas&#8221; parameter.<\/p>\n<p><em>(<strong>See also<\/strong> <a href=\"https:\/\/www.winhelponline.com\/blog\/automatically-elevate-batch-file-run-administrator\/\">How to Automatically Elevate a Batch file to Run it as Administrator?<\/a> for another auto-elevation method.)<\/em><!--more--><\/p>\n<h2>Launch a Vbscript elevated<\/h2>\n<p>Thanks to Jim Barry for tipping me off about the using <strong>runas<\/strong> argument in the <b>ShellExecute<\/b> method of Shell.Application object. Using Jim&#8217;s suggestions, my <a href=\"https:\/\/www.winhelponline.com\/scripts\/uac1.txt\">original script<\/a> was condensed down to a great deal. Use one of these methods to run VBScripts elevated.<\/p>\n<h3>Method 1<\/h3>\n<p>Here is a sample script that re-launches itself as administrator (elevated) using the <em><strong>runas<\/strong><\/em> parameter, if the script has no command-line arguments passed. When re-launching the script as administrator, simply pass a bogus argument so that the script does not run in a cyclic loop.<\/p>\n<pre>If WScript.Arguments.length = 0 Then\r\n   Set objShell = CreateObject(\"Shell.Application\")\r\n   'Pass a bogus argument, say [ uac]\r\n   objShell.ShellExecute \"wscript.exe\", Chr(34) &amp; _\r\n      WScript.ScriptFullName &amp; Chr(34) &amp; \" uac\", \"\", \"runas\", 1\r\nElse\r\n   'Add your code here\r\n\r\nEnd If<\/pre>\n<h3>Method 2<\/h3>\n<p>This method uses a launcher script which runs the main VBScript elevated using the <em><strong>runas<\/strong><\/em> verb.<\/p>\n<pre><code>Set objShell = CreateObject(\"Shell.Application\")\r\nSet FSO = CreateObject(\"Scripting.FileSystemObject\")\r\nstrPath = FSO.GetParentFolderName (WScript.ScriptFullName)\r\nIf FSO.FileExists(strPath &amp; \"\\MAIN.VBS\") Then\r\n     objShell.ShellExecute \"wscript.exe\", _\r\n        Chr(34) &amp; strPath &amp; \"\\MAIN.VBS\" &amp; Chr(34), \"\", \"runas\", 1\r\nElse\r\n     MsgBox \"Script file MAIN.VBS not found\"\r\nEnd If<\/code><\/pre>\n<p>You&#8217;ll see see the UAC elevation dialog.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3995\" src=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2007\/04\/uac-vbscript-elevation.png\" alt=\"automatically elevate vbscript runas\" width=\"456\" height=\"316\" \/><\/p>\n<p>Once user clicks <b>Continue<\/b> to approve, the main script is launched as administrator.<\/p>\n<p><em><strong>RELATED:<\/strong> <a href=\"https:\/\/www.winhelponline.com\/blog\/automatically-elevate-batch-file-run-administrator\/\">How to Automatically Elevate a Batch file to Run it as Administrator?<\/a><\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>With the introduction of User Account Control (UAC) in Windows Vista, you usually open an elevated Command Prompt in order to run batch files and scripts that need administrative privileges. Applications can make use of manifest files (using the RequireAdministrator flag) to automatically run elevated. For scripts, this article provides you some neat little tricks &#8230; <a title=\"How to Launch a Vbscript in Elevated Mode (Run as Administrator)\" class=\"read-more\" href=\"https:\/\/www.winhelponline.com\/blog\/vbscripts-and-uac-elevation\/\" aria-label=\"Read more about How to Launch a Vbscript in Elevated Mode (Run as Administrator)\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[7],"tags":[480],"class_list":["post-1512","post","type-post","status-publish","format-standard","hentry","category-windows","tag-scripts"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":3968,"url":"https:\/\/www.winhelponline.com\/blog\/automatically-elevate-batch-file-run-administrator\/","url_meta":{"origin":1512,"position":0},"title":"How to Automatically Elevate a Batch file to Run it as Administrator?","author":"Ramesh","date":"September 2, 2016","format":false,"excerpt":"To elevate batch files manually, you would right-click on it and choose Run as Administrator. Here is a way to automatically elevate a batch file that requires elevated privileges to run correctly. This is equivalent to choosing \"Run as Administrator\" by right-clicking a batch file. In either case, the UAC\u2026","rel":"","context":"In &quot;Windows&quot;","block_context":{"text":"Windows","link":"https:\/\/www.winhelponline.com\/blog\/category\/microsoft\/windows\/"},"img":{"alt_text":"bat file default runas elevated","src":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/09\/bat-elevated-2.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/09\/bat-elevated-2.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/09\/bat-elevated-2.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":127,"url":"https:\/\/www.winhelponline.com\/blog\/adding-the-run-as-administrator-option-for-vbs-and-js-files\/","url_meta":{"origin":1512,"position":1},"title":"Add Run as Administrator Context Menu Item for VBS and JS files","author":"Ramesh","date":"March 27, 2008","format":false,"excerpt":"By default, Windows does not include the Run as Administrator option in the context menu for Vbscript (.VBS) and JScript (.JS) files. So, to run a script elevated, you either need to launch the script from elevated Command Prompt window, or use the VBScript self-elevation method as described in article\u2026","rel":"","context":"In &quot;Windows&quot;","block_context":{"text":"Windows","link":"https:\/\/www.winhelponline.com\/blog\/category\/microsoft\/windows\/"},"img":{"alt_text":"add run as administrator context menu for vbs files","src":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/script_runas.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":123,"url":"https:\/\/www.winhelponline.com\/blog\/add-edit-hosts-file-option-in-the-context-menu\/","url_meta":{"origin":1512,"position":2},"title":"Add &#8220;Edit HOSTS file&#8221; option in the context menu","author":"Ramesh","date":"March 26, 2008","format":false,"excerpt":"The HOSTS file, originally introduced to resolve hostnames to IP addresses, is also an effective tool to block Malware. To modify the HOSTS file in Windows, you need to elevate Notepad.exe or any other text editor which you use. Otherwise, you'll see the following error when trying to save the\u2026","rel":"","context":"In &quot;Windows&quot;","block_context":{"text":"Windows","link":"https:\/\/www.winhelponline.com\/blog\/category\/microsoft\/windows\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/hosts3.gif?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":5203,"url":"https:\/\/www.winhelponline.com\/blog\/microsoft-fixes-eventvwr-exe-uac-bypass-exploit-windows-10-creators-update\/","url_meta":{"origin":1512,"position":3},"title":"Microsoft fixes Eventvwr.exe UAC Bypass Exploit in Windows 10 Creators Update","author":"Ramesh","date":"January 16, 2017","format":false,"excerpt":"In Windows 10 Creators Update preview build 15007, Microsoft seems to have fixed the UAC bypass method involving eventvwr.exe. First, how does this bypass work? When you're logged in as administrator, Windows binaries that have the execution level set to \"highestavailable\" and \"autoelevate\" property set to \"true\" in the manifest,\u2026","rel":"","context":"In &quot;Windows 10&quot;","block_context":{"text":"Windows 10","link":"https:\/\/www.winhelponline.com\/blog\/category\/microsoft\/windows\/windows-10\/"},"img":{"alt_text":"uac bypass exploit eventvwr.exe","src":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2017\/01\/uac-bypass-2.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2017\/01\/uac-bypass-2.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2017\/01\/uac-bypass-2.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":425,"url":"https:\/\/www.winhelponline.com\/blog\/run-bat-files-invisibly-without-displaying-command-prompt\/","url_meta":{"origin":1512,"position":4},"title":"How to run .BAT files invisibly, without displaying the Command Prompt window","author":"Ramesh","date":"August 5, 2008","format":false,"excerpt":"Batch files (.BAT) and Windows NT Command Script (.CMD) files run in console window when double-clicked. This means that the Command Prompt window will be visible until the .BAT or .CMD file execution is complete. To make .BAT or .CMD file execution less intrusive, you can configure it to run\u2026","rel":"","context":"In &quot;Utilities&quot;","block_context":{"text":"Utilities","link":"https:\/\/www.winhelponline.com\/blog\/category\/utilities\/"},"img":{"alt_text":"run batch file hidden - nircmd exec","src":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2008\/08\/nircmd-batch-file-hidden.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":117,"url":"https:\/\/www.winhelponline.com\/blog\/register-dlls-elevated-using-the-context-menu\/","url_meta":{"origin":1512,"position":5},"title":"Register and Unregister DLLs Elevated via Right-click Context Menu","author":"Ramesh","date":"March 25, 2008","format":false,"excerpt":"This post tells you how to add register and unregister commands to the right-click menu for DLL and OCX files in Windows Vista, 7, 8 and 10. To register a DLL or OCX file, you usually need to run regsvr32.exe from an elevated Command Prompt. Registering system DLLs from a\u2026","rel":"","context":"In &quot;Windows&quot;","block_context":{"text":"Windows","link":"https:\/\/www.winhelponline.com\/blog\/category\/microsoft\/windows\/"},"img":{"alt_text":"regsvr32 error 0x80004005","src":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2008\/03\/regsvr32-error-80004005.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/posts\/1512","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/comments?post=1512"}],"version-history":[{"count":0,"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/posts\/1512\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/media?parent=1512"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/categories?post=1512"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/tags?post=1512"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}