Running a batch as administrator

8

I need to create a batch to restart a service, it must include administrator credentials, something like this:

net stop miservicio [user][password]
net start miservicio [user][password]
set /p DUMMY = Presione enter para finalizar...

I tried in different ways and I have not obtained a result that helps me.

Beforehand, thank you community and greetings.

    
asked by Brandon Castillo 05.12.2018 в 17:54
source

3 answers

4

When executing the batch, do it in the following way, that is, at the end of your code add the following:

runas /user:Administrator archivo.batch

I hope it serves you.

    
answered by 05.12.2018 в 21:22
0

Try to precede the credentials with the following command: /user: It would be something like this:

net stop miservicio /user:[user] [password]
net start miservicio /user:[user] [password]
set /p DUMMY = Presione enter para finalizar...      
    
answered by 05.12.2018 в 18:40
0

Maybe with the 'sc' command

sc stop "miservicio" obj= "[.\Usuario]" password= "[Password]"
sc start "miservicio" obj= "[.\Usuario]" password= "[Password]"
set /p DUMMY = Presione enter para finalizar...

Please note:

  • Only User and Password should be replaced, do not remove []

  • Between obj / password and the value there must be a space so that | work.

answered by 20.12.2018 в 23:40