Run .bat as admin

Solved
MakaKiller Posted messages 54 Status Membre -  
MakaKiller Posted messages 54 Status Membre -
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 réponse

kaumune Posted messages 22594 Registration date   Status Contributeur Last intervention   5 156
 
Hi

runas /noprofile /user/hostname\Administrator cmd /c ipconfig
0
MakaKiller Posted messages 54 Status Membre 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
kaumune Posted messages 22594 Registration date   Status Contributeur Last intervention   5 156
 
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
MakaKiller Posted messages 54 Status Membre 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
bendrop Posted messages 12655 Registration date   Status Contributeur Last intervention   8 524 > MakaKiller Posted messages 54 Status Membre
 
Hello, you didn't put the quotes

"cmd /k ipconfig"

You must absolutely include them.

Best regards
0
MakaKiller Posted messages 54 Status Membre 8
 
Hi, thanks for your help

great, it works, thank you.
0