{"id":358,"date":"2009-12-04T15:47:13","date_gmt":"2009-12-05T00:47:13","guid":{"rendered":"http:\/\/www.insidethe.com\/blog\/?p=358"},"modified":"2009-12-04T15:47:30","modified_gmt":"2009-12-05T00:47:30","slug":"how-to-launch-a-wsh-vbscript-as-administrator-in-windows-7-and-vista","status":"publish","type":"post","link":"https:\/\/insidethe.com\/blog\/2009\/12\/how-to-launch-a-wsh-vbscript-as-administrator-in-windows-7-and-vista\/","title":{"rendered":"How to Launch a WSH VBScript as Administrator in Windows 7 and Vista"},"content":{"rendered":"<p>The example below launches a VB script as administrator on Windows 7 and Vista regardless if the context menu contains the &#8220;Run as administrator&#8221; option. Registry tweaks exist to add the run as administrator option to the context menu for .vbs files but this creates complications if the script is distributed to other people.<\/p>\n<p>When the script below is executed it checks to see if it was passed a command line argument named &#8220;elevated&#8221;. If it is not found the script recursively calls itself passing the elevated command line argument and requests to be run as administrator. The user is prompted to confirm the action and the restricted script exits leaving the escalated administrator script running. When the user grants permission the elevated argument is found and the script changes back from the %System32% working directory to the script where the script is located.<\/p>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">If WScript.Arguments.Named.Exists(&#8220;elevated&#8221;) = False Then<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\"><span style=\"white-space: pre;\"> <\/span>&#8216;Launch the script again as administrator<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\"><span style=\"white-space: pre;\"> <\/span>CreateObject(&#8220;Shell.Application&#8221;).ShellExecute &#8220;wscript.exe&#8221;, &#8220;&#8221;&#8221;&#8221; &amp; WScript.ScriptFullName &amp; &#8220;&#8221;&#8221; \/elevated&#8221;, &#8220;&#8221;, &#8220;runas&#8221;, 1<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\"><span style=\"white-space: pre;\"> <\/span>WScript.Quit<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">Else<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\"><span style=\"white-space: pre;\"> <\/span>&#8216;Change the working directory from the system32 folder back to the script&#8217;s folder.<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\"><span style=\"white-space: pre;\"> <\/span>Set oShell = CreateObject(&#8220;WScript.Shell&#8221;)<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\"><span style=\"white-space: pre;\"> <\/span>oShell.CurrentDirectory = CreateObject(&#8220;Scripting.FileSystemObject&#8221;).GetParentFolderName(WScript.ScriptFullName)<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\"><span style=\"white-space: pre;\"> <\/span>MsgBox &#8220;Now running with elevated permissions&#8221;<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">End If<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">&#8216;<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">&#8216;<\/div>\n<pre><span style=\"font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: 19px; white-space: normal; font-size: 13px;\">I<\/span>f WScript.Arguments.Named.Exists(\"elevated\") = False Then<\/pre>\n<pre><span style=\"white-space: pre;\">\t<\/span>'Launch the script again as administrator<\/pre>\n<pre><span style=\"white-space: pre;\">\t<\/span>CreateObject(\"Shell.Application\").ShellExecute \"wscript.exe\", \"\"\"\" &amp; WScript.ScriptFullName &amp; \"\"\" \/elevated\", \"\", \"runas\", 1<\/pre>\n<pre><span style=\"white-space: pre;\">\t<\/span>WScript.Quit<\/pre>\n<pre>Else<\/pre>\n<pre><span style=\"white-space: pre;\">\t<\/span>'Change the working directory from the system32 folder back to the script's folder.<\/pre>\n<pre><span style=\"white-space: pre;\">\t<\/span>Set oShell = CreateObject(\"WScript.Shell\")<\/pre>\n<pre><span style=\"white-space: pre;\">\t<\/span>oShell.CurrentDirectory = CreateObject(\"Scripting.FileSystemObject\").GetParentFolderName(WScript.ScriptFullName)<\/pre>\n<pre><span style=\"white-space: pre;\">\t<\/span>MsgBox \"Now running with elevated permissions\"<\/pre>\n<pre>End If<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The example below launches a VB script as administrator on Windows 7 and Vista regardless if the context menu contains the &#8220;Run as administrator&#8221; option. Registry tweaks exist to add the run as administrator option to the context menu for .vbs files but this creates complications if the script is distributed to other people. When [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[11,17],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Launch a WSH VBScript as Administrator in Windows 7 and Vista - Insidethe.com<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/insidethe.com\/blog\/2009\/12\/how-to-launch-a-wsh-vbscript-as-administrator-in-windows-7-and-vista\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Launch a WSH VBScript as Administrator in Windows 7 and Vista - Insidethe.com\" \/>\n<meta property=\"og:description\" content=\"The example below launches a VB script as administrator on Windows 7 and Vista regardless if the context menu contains the &#8220;Run as administrator&#8221; option. Registry tweaks exist to add the run as administrator option to the context menu for .vbs files but this creates complications if the script is distributed to other people. When [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/insidethe.com\/blog\/2009\/12\/how-to-launch-a-wsh-vbscript-as-administrator-in-windows-7-and-vista\/\" \/>\n<meta property=\"og:site_name\" content=\"Insidethe.com\" \/>\n<meta property=\"article:published_time\" content=\"2009-12-05T00:47:13+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2009-12-05T00:47:30+00:00\" \/>\n<meta name=\"author\" content=\"Jared\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jared\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/insidethe.com\/blog\/2009\/12\/how-to-launch-a-wsh-vbscript-as-administrator-in-windows-7-and-vista\/\",\"url\":\"https:\/\/insidethe.com\/blog\/2009\/12\/how-to-launch-a-wsh-vbscript-as-administrator-in-windows-7-and-vista\/\",\"name\":\"How to Launch a WSH VBScript as Administrator in Windows 7 and Vista - Insidethe.com\",\"isPartOf\":{\"@id\":\"https:\/\/insidethe.com\/blog\/#website\"},\"datePublished\":\"2009-12-05T00:47:13+00:00\",\"dateModified\":\"2009-12-05T00:47:30+00:00\",\"author\":{\"@id\":\"https:\/\/insidethe.com\/blog\/#\/schema\/person\/c18d4380c3bf0a5b931cc79af34e61cd\"},\"breadcrumb\":{\"@id\":\"https:\/\/insidethe.com\/blog\/2009\/12\/how-to-launch-a-wsh-vbscript-as-administrator-in-windows-7-and-vista\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/insidethe.com\/blog\/2009\/12\/how-to-launch-a-wsh-vbscript-as-administrator-in-windows-7-and-vista\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/insidethe.com\/blog\/2009\/12\/how-to-launch-a-wsh-vbscript-as-administrator-in-windows-7-and-vista\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/insidethe.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Launch a WSH VBScript as Administrator in Windows 7 and Vista\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/insidethe.com\/blog\/#website\",\"url\":\"https:\/\/insidethe.com\/blog\/\",\"name\":\"Insidethe.com\",\"description\":\"It is my space, but better than myspace\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/insidethe.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/insidethe.com\/blog\/#\/schema\/person\/c18d4380c3bf0a5b931cc79af34e61cd\",\"name\":\"Jared\",\"url\":\"https:\/\/insidethe.com\/blog\/author\/admin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Launch a WSH VBScript as Administrator in Windows 7 and Vista - Insidethe.com","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/insidethe.com\/blog\/2009\/12\/how-to-launch-a-wsh-vbscript-as-administrator-in-windows-7-and-vista\/","og_locale":"en_US","og_type":"article","og_title":"How to Launch a WSH VBScript as Administrator in Windows 7 and Vista - Insidethe.com","og_description":"The example below launches a VB script as administrator on Windows 7 and Vista regardless if the context menu contains the &#8220;Run as administrator&#8221; option. Registry tweaks exist to add the run as administrator option to the context menu for .vbs files but this creates complications if the script is distributed to other people. When [&hellip;]","og_url":"https:\/\/insidethe.com\/blog\/2009\/12\/how-to-launch-a-wsh-vbscript-as-administrator-in-windows-7-and-vista\/","og_site_name":"Insidethe.com","article_published_time":"2009-12-05T00:47:13+00:00","article_modified_time":"2009-12-05T00:47:30+00:00","author":"Jared","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Jared","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/insidethe.com\/blog\/2009\/12\/how-to-launch-a-wsh-vbscript-as-administrator-in-windows-7-and-vista\/","url":"https:\/\/insidethe.com\/blog\/2009\/12\/how-to-launch-a-wsh-vbscript-as-administrator-in-windows-7-and-vista\/","name":"How to Launch a WSH VBScript as Administrator in Windows 7 and Vista - Insidethe.com","isPartOf":{"@id":"https:\/\/insidethe.com\/blog\/#website"},"datePublished":"2009-12-05T00:47:13+00:00","dateModified":"2009-12-05T00:47:30+00:00","author":{"@id":"https:\/\/insidethe.com\/blog\/#\/schema\/person\/c18d4380c3bf0a5b931cc79af34e61cd"},"breadcrumb":{"@id":"https:\/\/insidethe.com\/blog\/2009\/12\/how-to-launch-a-wsh-vbscript-as-administrator-in-windows-7-and-vista\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/insidethe.com\/blog\/2009\/12\/how-to-launch-a-wsh-vbscript-as-administrator-in-windows-7-and-vista\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/insidethe.com\/blog\/2009\/12\/how-to-launch-a-wsh-vbscript-as-administrator-in-windows-7-and-vista\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/insidethe.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Launch a WSH VBScript as Administrator in Windows 7 and Vista"}]},{"@type":"WebSite","@id":"https:\/\/insidethe.com\/blog\/#website","url":"https:\/\/insidethe.com\/blog\/","name":"Insidethe.com","description":"It is my space, but better than myspace","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/insidethe.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/insidethe.com\/blog\/#\/schema\/person\/c18d4380c3bf0a5b931cc79af34e61cd","name":"Jared","url":"https:\/\/insidethe.com\/blog\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/insidethe.com\/blog\/wp-json\/wp\/v2\/posts\/358"}],"collection":[{"href":"https:\/\/insidethe.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/insidethe.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/insidethe.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/insidethe.com\/blog\/wp-json\/wp\/v2\/comments?post=358"}],"version-history":[{"count":4,"href":"https:\/\/insidethe.com\/blog\/wp-json\/wp\/v2\/posts\/358\/revisions"}],"predecessor-version":[{"id":362,"href":"https:\/\/insidethe.com\/blog\/wp-json\/wp\/v2\/posts\/358\/revisions\/362"}],"wp:attachment":[{"href":"https:\/\/insidethe.com\/blog\/wp-json\/wp\/v2\/media?parent=358"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/insidethe.com\/blog\/wp-json\/wp\/v2\/categories?post=358"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/insidethe.com\/blog\/wp-json\/wp\/v2\/tags?post=358"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}