Run .bat as admin

Solved
Hello,

I want to launch a .bat script in a session that does not have admin rights,

my script contains this:
runas /noprofile /user:hostname\Administrator cmd
ipconfig


When I run this .bat, it does prompt for the Administrator user's password but opens a new command prompt and does not continue executing the commands.

I would therefore like to be able to execute these commands requiring admin rights.

P.S.: ipconfig is just an example; I can already hear the "ipconfig doesn't require elevation" comments.

Configuration: Windows 7 / Chrome 49.0.2623.112

1 answer

  1. Hi

    runas /noprofile /user/hostname\Administrator cmd /c ipconfig
    0
    1. Hi,

      runas /noprofile /user:hostname\Administrator cmd /c ipconfig

      returns a runas syntax error and displays the command configuration information.
      And I can't find a /c option for runas.
      0
    2. runas /noprofile /user:hostname\Administrator "cmd /k ipconfig"


      tested on my machine === ok

      : between user and hostname and not /

      cmd /c if you want the cmd window to close
      0
    3. Thank you for your help
      here is the result in screenshot
      (for the ":" it's a transcription error in this post)

      http://www.cjoint.com/c/FDomnyhAiRR
      0
    4. Contributor
      @MakaKillerHello, you didn't put the quotes

      "cmd /k ipconfig"

      You must absolutely include them.

      Best regards
      0
    5. Hi, thanks for your help

      great, it works, thank you.
      0