{"id":1006,"date":"2014-06-04T21:53:40","date_gmt":"2014-06-05T02:53:40","guid":{"rendered":"http:\/\/montgomeryminds.com\/blog\/?p=1006"},"modified":"2015-02-20T16:27:20","modified_gmt":"2015-02-20T21:27:20","slug":"start-program-without-uac-useful-at-system-start","status":"publish","type":"post","link":"https:\/\/montgomeryminds.com\/blog\/start-program-without-uac-useful-at-system-start\/","title":{"rendered":"Start program WITHOUT UAC, useful at system start and in batch files (use task scheduler)"},"content":{"rendered":"<style type=\"text\/css\" media=\"all\">@import url(https:\/\/montgomeryminds.com\/css\/wp_blog_fixes.css);<\/style>\n<p>I like to run the search program <a href=\"http:\/\/www.voidtools.com\/\" title='\"Everything\" search program at http:\/\/www.voidtools.com\/' target=\"_blank\">Everything<\/a> (link valid 6\/4\/2014 but check <a href=\"http:\/\/techsupportalert.com\" target=\"_blank\">techsupportalert.com<\/a> for any updates) but it is a stand-alone executable downloaded from the internet so it triggers a UAC (User Account Control) warning.<\/p>\n<p>No biggie, but i also want it to start automatically when windows starts.  And i dont want to have to click UAC or have my customers click UAC <i>every time they start windows.<\/i><\/p>\n<p>I also might want to put commands that must be elevated in batch jobs (.bat files) when there&#8217;s no one there to click YES to the UAC.<\/p>\n<p>The workaround is to go thru task scheduler.  There you can set up a task to start with elevated privileges which won&#8217;t trigger a UAC.<\/p>\n<p>The article at <a href=\"http:\/\/www.winhelponline.com\/blog\/run-programs-elevated-without-getting-the-uac-prompt\/\" title=\"winhelponline article - http:\/\/www.winhelponline.com\/blog\/run-programs-elevated-without-getting-the-uac-prompt\/\" target=\"_blank\">http:\/\/www.winhelponline.com\/blog\/run-programs-elevated-without-getting-the-uac-prompt\/<\/a> contains the basic, but forgets some points.<\/p>\n<style>\n.tsk_my {\n   color: #60ff60;\n}\n<\/style>\n<p>My edits are in <span class=\"tsk_my\">green<\/span>:<\/p>\n<h1>Creating a Scheduled Task<\/h1>\n<p>1. Open Task Scheduler by <span class=\"tsk_my\">clicking the Windows Orb and typing &#8220;task&#8221; and selecting &#8220;Task Scheduler&#8221; from the search results,<\/span> or from Control Panel or by running the command <code>control schedtasks<\/code> from Start, Search box.<\/p>\n<p><span class=\"tsk_my\">2. Left-click Task Scheduler Library category in the left to select it (make it highlighted; or else you can&#8217;t do &#8220;New Folder&#8221; below)<\/span><\/p>\n<p>3. Right-click &#8220;Task Scheduler Library&#8221; category in the left, and choose <strong>New Folder<\/strong><\/p>\n<p>4. Name the folder as MyApps <span class=\"tsk_my\">(or whatever name you choose; you&#8217;ll use the same name again, below)<\/span><\/p>\n<p>5.  <span class=\"tsk_my\">Click the little triangle to the left of &#8220;Task Scheduler Library&#8221; to display the list of folders beneath it, including our newly created MyApps folder.<\/span><br \/>\n    Select the MyApps folder <span class=\"tsk_my\">(or whatever you named it) by left clicking on it once<\/span>.<\/p>\n<p>6. In the Actions pane on the right, click <strong>Create Task&#8230;<\/strong><\/p>\n<p>7. Type a name for the task that you want to create.  <span class=\"tsk_my\">You&#8217;re going to have to type this again later, so for convenience, keep it short and dont use any spaces<\/span>.<\/p>\n<p>8. Enable the option <strong>Run with highest privileges.<\/strong> This is an important step.  <span class=\"tsk_my\">In fact the key to the whole thing.<\/span><\/p>\n<p><span class=\"tsk_my\">8.a. (FYI The &#8220;Hidden&#8221; checkbox refers to only viewing tasks in the task scheduler; there is way to show or now show hidden tasks when in task scheduler; This Hidden settings does not make the task hidden in any way when it runs.)<\/span><\/p>\n<p>9. Select the <strong>Action<\/strong> tab<\/p>\n<p>10. Click <strong>New<\/strong><\/p>\n<p>11. Click <strong>Browse<\/strong>&#8230; to select the program (Example: Regedit.exe) you want to run, and mention the parameters <span class=\"tsk_my\">(called arguments in task scheduler)<\/span>. required if any, for the application. (For example, to run a .REG file, select Regedit.exe and mention the parameter <span class=\"tsk_my\">(argument)<\/span> as &#8220;\/s filename.reg&#8221; without the quotes.  <span class=\"tsk_my\">Another example: my Everything program takes a -startup argument to start in the system tray rather than with a window.<\/span>)<\/p>\n<p>To run Services MMC applet, browse and select MMC.EXE and type services.msc in the Add arguments (optional) field.<\/p>\n<p><span class=\"tsk_my\">12. Select the <strong>Conditions<\/strong> tab<\/span><\/p>\n<p><span class=\"tsk_my\">12.a. UNcheck &#8220;Start the task only if the computer is on AC power&#8221;<\/span><\/p>\n<p><span class=\"tsk_my\">13. Select the <strong>Settings<\/strong> tab<\/span><\/p>\n<p><span class=\"tsk_my\">13.a UNcheck &#8220;Stop the task if it runs longer than&#8221;<\/span><\/p>\n<p><span class=\"tsk_my\">13.b at the bottom there is &#8220;If the task is already running, then the following rule applies:&#8221; You can choose whatever you want here.<\/span><\/p>\n<p><span class=\"tsk_my\">If when it&#8217;s running you want to not start another one, select &#8220;Do not start a new instance&#8221;.<\/span><\/p>\n<p><span class=\"tsk_my\">If when it&#8217;s running you want might want start another one running simultaneously, select &#8220;Run a new instance in parallel&#8221;.<\/span><\/p>\n<p><span class=\"tsk_my\">If when it&#8217;s running you want to end the one that&#8217;s currently running, and start another one running, select &#8220;Stop the existing instance&#8221;.<\/span><\/p>\n<p><span class=\"tsk_my\">I suppose &#8220;Queue a new instance&#8221; is helpful, but i can&#8217;t think of an example right now.<\/span><\/p>\n<p>Note, you can export this to an <a href=\"#nouac_xml\">xml file (see below)<\/a> and then import it into another system<\/p>\n<h1>Creating a Scheduled Task via cmd line <code>schtasks<\/code><\/h1>\n<p>(NOTE: this method is <a href=\"#nouac_not_as_good\">NOT AS GOOD&#8211;see below<\/a>)<\/p>\n<p>Alternatively, you can create a task via the cmd line <code>schtasks<\/code> :<\/p>\n<pre>\r\nschtasks \/create \/sc once \/tn cmd_elev \/tr cmd \/rl highest \/st 00:00\r\n<\/pre>\n<dl>\n<dt><code>schtasks<\/code>\n<\/dt>\n<dd>invoke the schtasks.exe cmd line program\n<\/dd>\n<dt><code>\/create<\/code>\n<\/dt>\n<dd>schtasks can also query, delete, etc; we want to <i>create<\/i> a task\n<\/dd>\n<dt><code>\/sc once<\/code>\n<\/dt>\n<dd>how often to run; we&#8217;re not creating a repetitive task; in fact we dont want to run it at all, just set it up to be run manually, but that option does not appear to be available, so &#8220;once&#8221; is the closest (see explanation at \/sc starttime)\n<\/dd>\n<dt><code>\/tn cmd_elev<\/code>\n<\/dt>\n<dd><code>\/tn<\/code> stands for Task Name and you can name it anything you want (but you have to use the same name when you later invoke <code>\/run<\/code>\n<\/dd>\n<dt><code>\/tr cmd<\/code>\n<\/dt>\n<dd>the command to run, in this case the <code>cmd.exe<\/code> program, aka command prompt\n<\/dd>\n<dt><code>\/rl highest<\/code>\n<\/dt>\n<dd>Why we came to the party. <code>\/rl<\/code> stands for Run at privilege Level; and we want the <code>highest<\/code> priv level<\/p>\n<\/dd>\n<dt><code>\/st 00:00<\/code>\n<\/dt>\n<dd><code>\/st<\/code> stands for Start Time; dont want a start time, but it appears to require one. When you create thru the GUI you dont have to have a trigger at all, but via cmd line you seem to (or was it just me?). I just put in 00:00 (format is HH:MM) which is never in the future, which means it&#8217;ll trigger a warning<\/p>\n<pre>\r\nWARNING: Task may not run because \/ST is earlier than current time.\r\n<\/pre>\n<p>Yeah, that&#8217;s what i want. (NOTE: love those microsoft guys: it&#8217;s a nit, but when the time is EQUAL to the current time, you get the warning)\n<\/dd>\n<\/dl>\n<p>If all goes well, you should see<\/p>\n<pre>\r\nSUCCESS: The scheduled task \"cmd_elev\" has successfully been created.\r\n<\/pre>\n<p>or whatever name you called it.<\/p>\n<p>If you re-run the line (let&#8217;s say you were experimenting \ud83d\ude09 you will get the warning<\/p>\n<pre>\r\nWARNING: The task name \"cmd_elev\" already exists. Do you want to replace it (Y\/N)? y\r\n<\/pre>\n<p>You can safely say Y to this.<\/p>\n<p><a name=\"nouac_not_as_good\"><\/a><\/p>\n<div style=\"background-color: #302300\">NOTE: this method is NOT AS GOOD as creating thru the GUI. At least i could not find the switches to set some important things.<\/div>\n<p> Namely,<\/p>\n<ul>\n<li><span class=\"bold_lite\">&#8220;start the task only if the computer is on ac power&#8221;<\/span> will be checked in the conditions tab; not ideal\n<\/li>\n<li><span class=\"bold_lite\">&#8220;stop the task if it runs longer than [time]&#8221;<\/span> where time defaults to &#8220;3 days&#8221; will be checked in the setting tab; not ideal\n<\/li>\n<\/ul>\n<h1>Launching a Scheduled Task item manually<\/h1>\n<p>To run a scheduled task item manually, use the <code>schtasks.exe<\/code> command-line tool that comes with Windows. For example, to launch the Services console task that you already created, use the following command:<\/p>\n<pre>\r\nSCHTASKS.EXE \/RUN \/TN <span class=\"tsk_my\">MyApps\\<\/span>REGEDIT\r\n<\/pre>\n<p>Note: Where MyApps\\REGEDIT is the <span class=\"tsk_my\">name you chose for the folder and<\/span> Taskname. You\u2019ll need to enclose the task name within double-quotes if the task name contains blank spaces in between. (Example: SCHTASKS.EXE \/RUN \/TN <span class=\"tsk_my\">folder\\<\/span>&#8220;Name of the Task&#8221;) If the folder has spaces, you&#8217;ll have to enclose that in double-quotes; perhaps best to enclose the whole thing. (Example: SCHTASKS.EXE \/RUN \/TN <span class=\"tsk_my\">&#8220;folder\\<\/span>Name of the Task&#8221;)<\/p>\n<h1>Creating Shortcuts to run each Task<\/h1>\n<p>You can create a Desktop shortcut for each scheduled task item you&#8217;ve created earlier. Right-click on the Desktop and choose New, Shortcut. Type the command-line (say, SCHTASKS.EXE \/RUN \/TN <span class=\"tsk_my\">MyApps\\<\/span>REGEDIT). Mention a name for the shortcut and click Finish.<\/p>\n<h1>Run the task minimized<\/h1>\n<p>As <code>Schtasks.exe<\/code> is a console utility, you\u2019ll see the Command Prompt window opening and closing quickly whenever you run the shortcut. So, you may configure the shortcut to run in a minimized window state, in the the shortcut properties.<\/p>\n<ul>\n<li>    Right-click on the shortcut and click <strong>Properties.<\/strong>\n<\/li>\n<li>    In the <strong>Run<\/strong> drop-down options, <span class=\"tsk_my\">change the selection from &#8220;Normal Window&#8221; to<\/span> <strong>Minimized<\/strong>.\n<\/li>\n<li>    Click <strong>OK.<\/strong>\n<\/ul>\n<p>Note: In the shortcut properties, you may want to click Change Icon and assign appropriate icon for the shortcut. The icons should be present inside the executable itself, in most cases. For Regedit.exe, browse to Regedit.exe and choose an icon. You may also browse the shell32.dll and imageres.dll files for additional icons.<\/p>\n<p><a name=\"nouac_xml\"><\/a><\/p>\n<h1>xml file<\/h1>\n<p>Once you set up a task the way you like it via the GUI <a href=\"#nouac_not_as_good\">(recommended method)<\/a>, you can export it to an xml file so that it&#8217;s easier to set up on the next system.<\/p>\n<p>Here&#8217;s my xml file for (Search) Everything. Filename ends in .xml.txt so change it to just .xml befor importing to task scheduler.  <a href=\"https:\/\/montgomeryminds.com\/files\/start_search_everything.xml.txt\"><\/code>start_search_everything.xml.txt<\/code><\/a><\/p>\n<h1>Other Methods<\/h1>\n<p>There are at least three other compelling methods.<\/p>\n<h2>The first two come from<\/h2>\n<ul>\n<li>stackoverflow : <a title=\"stackoverflow : Open an elevated cmd using command line for Windows - http:\/\/stackoverflow.com\/questions\/19098101\/open-an-elevated-cmd-using-command-line-for-windows\" href=\"http:\/\/stackoverflow.com\/questions\/19098101\/open-an-elevated-cmd-using-command-line-for-windows\">Open an elevated cmd using command line for Windows<\/a>\n<ul>\n<li>&lt;<a title=\"stackoverflow : Open an elevated cmd using command line for Windows - http:\/\/stackoverflow.com\/questions\/19098101\/open-an-elevated-cmd-using-command-line-for-windows\" href=\"http:\/\/stackoverflow.com\/questions\/19098101\/open-an-elevated-cmd-using-command-line-for-windows\">http:\/\/stackoverflow.com\/questions\/19098101\/open-an-elevated-cmd-using-command-line-for-windows<\/a>&gt;\n   <\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>1. NirSoft NirCmd<\/h2>\n<p><code>nircmdc<\/code> has an <code>elevate<\/code> cmd<\/p>\n<pre>nircmdc elevate cmd<\/pre>\n<h2>2. SysInternals PsExec<\/h2>\n<p>Part of PsTools suite.<\/p>\n<p>psexec.exe -accepteula -h -u &#8220;$username&#8221; -p &#8220;$password&#8221; cmd.exe<\/p>\n<p>The &#8220;-h&#8221; switch is the one doing the magic:<\/p>\n<blockquote><p>-h If the target system is Vista or higher, has the process run with the account&#8217;s elevated token, if available.<\/p><\/blockquote>\n<h2>The third comes from<\/h2>\n<ul>\n<li>Matt&#8217;s answer to stackoverflow question : <a href=\"stackoverflow : How can I auto-elevate my batch file, so that it requests from UAC administrator rights if required? - http:\/\/stackoverflow.com\/questions\/7044985\/how-can-i-auto-elevate-my-batch-file-so-that-it-requests-from-uac-administrator\/12264592#12264592\" title=\"http:\/\/stackoverflow.com\/questions\/7044985\/how-can-i-auto-elevate-my-batch-file-so-that-it-requests-from-uac-administrator\/12264592#12264592\">How can I auto-elevate my batch file, so that it requests from UAC administrator rights if required?<\/a>\n<ul>\n<li>&lt;<a title=\"stackoverflow : How can I auto-elevate my batch file, so that it requests from UAC administrator rights if required? - http:\/\/stackoverflow.com\/questions\/7044985\/how-can-i-auto-elevate-my-batch-file-so-that-it-requests-from-uac-administrator\/12264592#12264592\" href=\"http:\/\/stackoverflow.com\/questions\/7044985\/how-can-i-auto-elevate-my-batch-file-so-that-it-requests-from-uac-administrator\/12264592#12264592\">http:\/\/stackoverflow.com\/questions\/7044985\/how-can-i-auto-elevate-my-batch-file-so-that-it-requests-from-uac-administrator\/12264592#12264592<\/a>&gt;\n    <\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>3. vbs or PowerShell to elevate<\/h2>\n<p>key lines are to use the visual basic script \/ vbscript command <code>UAC.ShellExecute<\/code> to perform the elevation, create a new cmd (command prompt), and re-run the original bat file, now elevated. Does that by writing a <\/code>.vbs<\/code> file:<\/p>\n<pre>\r\nECHO UAC.ShellExecute \"!batchPath!\", \"ELEV\", \"\", \"runas\", 1 >> \"%temp%\\OEgetPrivileges.vbs\"\r\n\"%temp%\\OEgetPrivileges.vbs\"\r\n<\/pre>\n<p>Or, you can use PowerShell to elevate:<\/p>\n<pre>\r\nif '%errorlevel%' == '0' ( goto gotPrivileges ) else ( powershell \"saps -filepath %0 -verb runas\" >nul 2>&1)\r\n<\/pre>\n<h1>Elevated command prompt and mapped drives<\/h1>\n<p>One problem you might encounter when using this method if you&#8217;re running a batch file (.bat) in elevated mode, is: <a title=\"Mapped drives (incl net use) missing from elevated processes eg UAC cmd run as administrator- https:\/\/montgomeryminds.com\/blog\/mapped-drives-incl-net-use-missing-from-elevated-processes-eg-uac-cmd-run-as-administrator\/\" href=\"https:\/\/montgomeryminds.com\/blog\/mapped-drives-incl-net-use-missing-from-elevated-processes-eg-uac-cmd-run-as-administrator\/\">Mapped drives (incl net use) missing from elevated processes eg UAC cmd run as administrator<\/a>.  Fortunately, there&#8217;s some solutions in that blog post.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I like to run the search program Everything (link valid 6\/4\/2014 but check techsupportalert.com for any updates) but it is a stand-alone executable downloaded from the internet so it triggers a UAC (User Account Control) warning. No biggie, but i &hellip; <a href=\"https:\/\/montgomeryminds.com\/blog\/start-program-without-uac-useful-at-system-start\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[5,3],"tags":[],"_links":{"self":[{"href":"https:\/\/montgomeryminds.com\/blog\/wp-json\/wp\/v2\/posts\/1006"}],"collection":[{"href":"https:\/\/montgomeryminds.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/montgomeryminds.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/montgomeryminds.com\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/montgomeryminds.com\/blog\/wp-json\/wp\/v2\/comments?post=1006"}],"version-history":[{"count":24,"href":"https:\/\/montgomeryminds.com\/blog\/wp-json\/wp\/v2\/posts\/1006\/revisions"}],"predecessor-version":[{"id":1318,"href":"https:\/\/montgomeryminds.com\/blog\/wp-json\/wp\/v2\/posts\/1006\/revisions\/1318"}],"wp:attachment":[{"href":"https:\/\/montgomeryminds.com\/blog\/wp-json\/wp\/v2\/media?parent=1006"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/montgomeryminds.com\/blog\/wp-json\/wp\/v2\/categories?post=1006"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/montgomeryminds.com\/blog\/wp-json\/wp\/v2\/tags?post=1006"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}