WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

UAC

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Run As Admin WinBatch Script With UAC On

 Keywords:  Run As Admin RunAs Administrator WinBatch WBT Script UAC Scheduler Schedule Task Interactive

Run As Admin WinBatch Script With UAC On

Here is a UAC-friendly method to have your WinBatch script Run As Administrator.

The trick is to use the Task Scheduler. Note: you must be an Administor in order to create the scheduled task.:

  1. Open the Task Scheduler (also known as "Schedule tasks" ).
  2. Select "Create a Basic Task".
  3. Give it a name (like "Run as admin WBT"). You can also give an optional "description". Click Next.
  4. Specify to have it run "When I log on".
  5. Specify that you want it to "Start a program", and then point it towards your WinBatch script.
  6. Its a good idea to also specify a Start-in directory (the directory that contains the script and any included files). Click Next.
  7. Check off the "Open the Properties dialog for this task when I click finish".
  8. Click the Finish button and the Properties dialog will appear.
  9. Go to the Conditions tab and make sure none of the checkboxes under the Power category are checked off; this will ensure the script still launches if you are on a laptop and not plugged into AC power.
  10. To have your script "Run as admin", on the General tab check the box next to "Run with highest privileges".
  11. Make sure the user account specified is an administrator account or the local system account (NT AUTHORITY\SYSTEM).
Now your WinBatch script will start automatically as soon as you log into Windows; even when UAC is enabled.

Keep in mind that the task scheduler runs all scripts in non-interactive mode. So you will need to make sure that your script doesn't attempt to display anything or interact with any desktop windows ( Sendkey or Mouse ). You will also want to make sure the script runs quietly ( doesn't display any messages or error messages). Simply add IntControl(38,1,DirScript():'wberrorlog.txt',0,0) to the beginning of the script to make sure it runs in quiet mode.

Possible interactive mode workaround The fix is to create your Scheduled Task in interactive mode. Unfortunately you cannot do this through the GUI; it must be done through the command line. You can use the following command to create a new interactive scheduled task:

useracct = 'domain\user'
taskname = 'Run as admin WBT'
wbtscript = 'c:\temp\sample.wbt'
ShellExecute( 'schtasks', '/Create /RU "':useracct:'" /SC ONLOGON /TN "':taskname:'" /TR "':wbtscript:'" /IT /V1', '', @NORMAL, '')
The /IT switch is what tells it to create the task in Interactive mode. The /V1 switch actually specifies to create the task as a Windows XP/2000/Server 2003 compatible task, and has the added benefit of making the task run as admin by default with the Start In directory specified as the directory holding the file to run.
Article ID:   W18318
Filename:   Run As Admin WinBatch Script With UAC On.txt
File Created: 2013:11:13:10:27:18
Last Updated: 2013:11:13:10:27:18