program elevation from command line

Discussion in 'Suggestions' started by jbutare, Oct 30, 2009.

  1. jbutare

    jbutare

    Messages:
    13
    Hi, after a small run in with a virus I have decided to enable UAC. The key feature holding me back was the ability to run a program elevated from the command line (unix like "sudo" capability).

    John Robbins has written a simple "elevate" program (for use with Take Command) that would be extremely useful as an internal function - part of start maybe.

    I have wrapped up elevate with a simple batch file that starts Take Command commands in a new Take Command shell, and external commands directly, this would also be useful in take command.

    Start a command as administrator.
    usage: sudo [/wait|/hide|/pause] <command>
    - /wait - wait for the elevated program to finish
    - /hide - hide the elevated command line program
    - /pause - pause before ending the elevated command line program

    :start

    REM Start an elevated command prompt
    iff %# == 0 then
    elevate.exe %wait "%ComSpec"
    return 0
    endiff

    set command=%1

    REM Check for a valid program
    which %@quote[%command] |& egrep -i "is an unknown" >& nul
    iff %? == 0 then
    EchoErr %command is an unknwon command.
    return 1
    endiff

    REM Run an external (not Take Command) program elevated
    which %@quote[%command] |& egrep -i "is an external" >& nul
    iff %? == 0 then
    elevate.exe %wait %$
    return 0
    endiff

    REM Run a Take Command program elevated
    elevate.exe %wait "%ComSpec" /c %hidden %$ %@if[ defined pause ,`&` pause]

    return 0</command>

Share This Page