locked
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
    Nakul
     
     
    Thursday, June 23, 2011 2:52 PM

Answers

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:

    http://social.technet.microsoft.com/Forums/en-US/ITCG/thread/97036c0a-d98f-4991-af67-bd69deb3986e

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

    http://blogs.msdn.com/b/aaron_margosis/archive/2007/06/29/faq-why-can-t-i-bypass-the-uac-prompt.aspx

    Bill

    • 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".


    Edit:

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

    http://blogs.msdn.com/b/aaron_margosis/archive/2007/07/01/scripting-elevation-on-vista.aspx

    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).

    HTH,

    Bill

    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.

    Hi,

    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.

    Bill

    Monday, June 27, 2011 3:04 PM