2

I want to execute serve -s build from .bat file as admin, this is my .bat file:

@ECHO OFF  
cd "C:\Users\user\Desktop\Brabender\build-20220517T114506Z-001"  
serve -s build

It works if I manually run it as admin, but I need it to run from Windows Startup Folder everytime the system starts, any ideas how to do it as admin automatically?

Compo
  • 36,585
  • 5
  • 27
  • 39
Anna
  • 33
  • 5

1 Answers1

0

Some minor changes to your batch file, adding /d to the cd command

@echo off
cd /d "C:\Users\user\Desktop\Brabender\build-20220517T114506Z-001"  
serve -s build

Assuming we call the file something like serve-build-script.bat, run from cmd.exe

schtasks /create /tn "Serve-Build" /tr "c:\<Path-to-Batch-file>\batchfile-name.bat" /sc onstart /ru "user" /rp "password" /np /f

The correct version updated as per confirmation from the chat.

Gerhard
  • 22,678
  • 7
  • 27
  • 43
  • Hi Gerard, thanks for your reply. I followed your instrucions, an scheduled task has been created but it is not running, when I start the system it reminds in state "Ready" in the Task Scheduler. Other tasks that I have created in the same way are running (example: run java -jar in a .bat file) – Anna Sep 05 '22 at 09:04
  • Is there anyway to run it on startup without human interaction when system starts or reboots from an update? wihout starting session? – Anna Sep 05 '22 at 09:16
  • Yes that is the requirement, I need to run every startup without starting he session, but it is not working... :( – Anna Sep 05 '22 at 12:10
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/247807/discussion-between-anna-and-gerhard). – Anna Sep 06 '22 at 05:53
  • For those looking for the right answer, this worked for me: schtasks /create /tn "Serve-Build" /tr "c:\\batchfile-name.bat" /sc onstart /ru "username" /rp "password" /np /f – Anna Sep 06 '22 at 11:23
  • I have updated the answer with that option, @Anna. Thank you – Gerhard Sep 06 '22 at 11:24