Run .bat as admin

Solved
MakaKiller Posted messages 54 Status Member -  
MakaKiller Posted messages 54 Status Member -
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. kaumune Posted messages 22605 Registration date   Status Contributor Last intervention   5 158
     
    Hi

    runas /noprofile /user/hostname\Administrator cmd /c ipconfig
    0
    1. MakaKiller Posted messages 54 Status Member 8
       
      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. kaumune Posted messages 22605 Registration date   Status Contributor Last intervention   5 158
       
      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. MakaKiller Posted messages 54 Status Member 8
       
      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
      1. bendrop Posted messages 12662 Registration date   Status Contributor Last intervention   8 527 > MakaKiller Posted messages 54 Status Member
         
        Hello, you didn't put the quotes

        "cmd /k ipconfig"

        You must absolutely include them.

        Best regards
        0
    4. MakaKiller Posted messages 54 Status Member 8
       
      Hi, thanks for your help

      great, it works, thank you.
      0