M
M
MaxLich2017-12-26 15:16:03
Command line
MaxLich, 2017-12-26 15:16:03

How to execute a command in command line with administrator rights in Windows 10?

Hello. You need to write a script that will restart the service. You can only restart the service with administrator rights. What needs to be written in the script so that each command is executed with administrator rights?
I tried runas /user:Admin "net stop ServiceName", but it doesn't help (it doesn't stop the service and asks for a password).
UPD: The person here suggested using a shortcut, and specify in its properties that you need to run it with administrator rights. This partially helped. My script itself is called from a program written in Java, so I cannot interact directly with the commands. So, when I did this, the service began to stop successfully, but at the same time it asked for a username and password. It would be desirable to drive in login and the password at once in a script. It's just that this script should work automatically.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
LAG_LAGbI4, 2017-12-27
@LAG_LAGbI4

www.oszone.net/10594#800

D
Denis, 2017-12-27
@denilenko

Try it through the task scheduler:
0. In the properties of the task, check the box "Run with the highest rights" (you will need to enter the administrator password once)
1. Create a trigger "Start task on event"
2. Then I think you'll figure it out. ))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question