administrator command prompt RRS feed

  • Question

  • Hello all

    basically i need a script or a batch file that runs on windows 7 or windows vista

    to open up a command prompt and execute command in that batch file in administrator mode

    please do not suggest me any manually methods like

    Right-click and select "run as administrator".
    enter cmd in the search box on the start menu and pressing ctrl+shift+enter.
    Waiting for your reply eagerly
    Best regards
    Thursday, June 23, 2011 2:52 PM


All replies

  • runas /user:DOMAIN\SAM cmd


    Paul Frankovich
    Thursday, June 23, 2011 2:55 PM
  • Hi,

    If your question is "how do I force an elevation prompt from script," see the solutions in this thread:


    If your question is "how do I bypass the elevation prompt," the answer is "you don't." See this blog post:



    • Proposed as answer by thepip3r Thursday, June 23, 2011 7:30 PM
    • Marked as answer by Richard MuellerMVP Sunday, July 10, 2011 5:41 PM
    Thursday, June 23, 2011 3:05 PM
  • I'm pretty sure I understand what you're asking because I looked into this a few weeks ago.  And if you're asking:  How do you elevate something as "Run as Administrator", <del>the answer is, you can't.</del>  I'll see if I can find the document/blog I read that gave me that unfriendly answer.

    If you want to execute something as a different user (say a user with Administrator rights), use Paul's example above.  BUT in Vista and Win7, this is NOT the same context as "Run as Administrator".


    I stand corrected.  In my blogging experience, Aaron Margosis is pretty much the Internet-definitive reference for runas:


    it can't be done natively but through the use of a little js or vbs it can...

    Thursday, June 23, 2011 6:57 PM
  • Hi thepip3r,

    The first link I posted (the thread Forcing a UAC challenge for a VB Script in this forum) has the same link to Aaron Margosis' blog, along with a VBScript example and an executable I wrote that might be useful in certain circumstances I noted in that thread (namely, if you need to wait for the elevated application to complete and/or retrieve its exit code).



    Thursday, June 23, 2011 7:24 PM
  • I'm not on a box with UAC right now, but does 'psexec \\%computername% -h foo.exe' work? E.g. It spawns a local (loopback), elevated process.
    Friday, June 24, 2011 12:28 AM
  • I'm not on a box with UAC right now, but does 'psexec \\%computername% -h foo.exe' work? E.g. It spawns a local (loopback), elevated process.


    That does not work because psexec installs a driver (the installation of which requires elevation). If the process from which you execute psexec.exe is not itself running elevated, the driver installation fails.


    Monday, June 27, 2011 3:04 PM