How do I elevate permissions from within a batch script in Windows 7 or 2008?

6,364

Using only a batch file? AFAIK, impossible. You'll need to fire off a VBscript or JScript, which can use the Shell.Execute.

You can look at some examples here or donwload the Elevate Powertoys, which are premade VBscripts and batchfiles you can use.

Also included in the Elevate Powertoys are examples on how to self elevate a batfile.

Share:
6,364

Related videos on Youtube

Andrey
Author by

Andrey

Updated on September 18, 2022

Comments

  • Andrey
    Andrey almost 2 years

    Possible Duplicate:
    Batch file - start program with admin rights

    I'm writing a batch script that requires administrator permissions to execute, so to start it I need to right-click and select "Run as Administrator". Is there a way to elevate permissions form within the script instead, like "su" in *nix?

    • Ƭᴇcʜιᴇ007
      Ƭᴇcʜιᴇ007 over 12 years
      If batch files could elevate themselves and circumvent UAC, then malware would have a heyday. :)
    • surfasb
      surfasb over 12 years
      @techie007: This is true. But usually when folks say they need to elevate a script, it doesn't mean to circumvent UAC. Batchfiles have no built in method of even invoking a command that requires admin privileges. And the linked duplicate needs to be updated as that no longer works with UAC.
    • Andrey
      Andrey over 12 years
      I was thinking more along the lines of triggering UAC dialog box