Home > HowTo's > Autorun as Administrator in Vista

Autorun as Administrator in Vista

January 18th, 2009 Leave a comment Go to comments

When asked how to automate the installation of software the other day I was a little dismayed that no-one seemed to have covered the topic of auto-running a batch file from a USB disk as an administrative user.

Admin level access is obviously required in order to install software without relentless ‘Program X requires administrative access’ UAC prompts.

Like most things in Vista the solution is exceptionally stupid and requires significant trips with Google to rather obscure second-hand Microsoft knowledge base articles.

The overview is something like this:

Autorun as admin process diagram

First create the autorun.inf file:

?Download autorun.inf
label=Setup computer from USB disk

So this file simply sets up the autorun.inf file which contains exactly what to list in the Vista ‘Autoplay’ dialog when the USB disk is inserted. You will probaly want to rename the ‘Label’ line and perhaps put a pretty icon on your disk called ‘autorun.ico’.

Now create your actual batch file that you wish to run as admin and call it ‘setup.bat’.

As a small note of caution. For some reason Vista does not change to this files active working directory when executing. I can really think of no reason this behavior exists so you might want to add the following rather cryptic command as the first in the batch file. This changes the active directory into the current batch file (in this case ‘setup.bat’) directory.

?Download setup.bat
cd /d %~dp0

There obvious when you think about it isn’t it. Shame on you for not knowing about the handy and invisible shell variable “~dp0”. I am sure there is a long and interesting story about why this variable is so called and why it doesnt show up with the rest of things when you type ‘set’. This is why I switched to Linux some time ago.

Anyway, now we’ve done that create a shortcut to the ‘Setup.bat’ file and rename it to ‘setup.lnk’ (remember that the ‘.lnk’ bit will always be invisible to you anyway so when you rename in explorer all you will see is the ‘setup’ bit sans extension).

Open the shortcuts properties and hit the ‘Advanced’ button. Tick the ‘Run as Administrator’ box.

Finally, lets join it all together by creating the ‘Invoke.bat’ file which runs the shortcut (which will in turn run the ‘setup.bat’ program after asking via UAC for administrative permission).

?Download invoke.bat

Now save everything and remove you disk (safely) and re-insert. You will now be able to run the ‘setup.bat’ file which should contain all your auto-install scripts after a UAC admin prompt. Yey.

Categories: HowTo's Tags: , ,
  1. John
    May 18th, 2009 at 12:00 | #1

    Autorun as Administrator in Vista

    Great article – thanks. I am needing to use my USB on both Vista and XP and found that I needed to amend the invoke.bat file:

    Ver >%temp%\OSVer.Txt
    FIND “[Version 6.” %temp%\OSVer.Txt > NUL
    ) ELSE (

    • May 18th, 2009 at 12:09 | #2


      Makes you wish that there was a suitable Bash equivalent in Windows doesn’t it?

      And no, PowerShell doesn’t count.

  2. catalist
    May 14th, 2011 at 13:25 | #3

    rename file to setup_NAME

  1. No trackbacks yet.