简体   繁体   中英

Starting batch file from Task scheduler point to C:\Windows\system32

I want to start a service which requires to work open cmd console.

When I manually after login start a batch script from author of service (It cannot be closed - otherwise the service stop working)

@echo off
color 0
echo Preparation aplication Currenda Statistic Portal Version: 0.1 Beta (Raport) to start ...
echo Enter port, on which aplication will be available in web browser
set /p port="Enter port: "
echo Aplication will be started at: http://localhost:%port%
"libraries\bin\java.exe" -Xms2G -Xmx3G -jar raportgmin.jar --server.port=%port%

Evething works fine and the entered configuration (connections to database) saves in:

D:\Statistic Portal\data\databases

But I want to start this service automatically so I changed the script like below

@echo off
color 0
echo Preparation aplication Currenda Statistic Portal Version: 0.1 Beta (Raport) to start ...

echo Aplication will be started at: http://localhost:9090
"D:\Statistic Portal\libraries\bin\java.exe" -Xms2G -Xmx3G -jar "D:\Statistic Portal\raportgmin.jar" --server.port=9090

and starts it from Schedule Task - the service works fine but the configuration file saves in:

C:\Windows\system32\data\databases

My question

What I need to change in order to service start from schedule task and saves configuration files in

D:\Statistic Portal\data\databases

not in

C:\Windows\system32\data\databases

Thank you very much..

I edit batch file following your advice and everything seems to be work as I need and want.

One more time thank you.

@echo off
CD /D "D:\Statistic Portal"
color 0
"D:\Statistic Portal\libraries\bin\java.exe" -Xms2G -Xmx3G -jar raportgmin.jar --server.port=9090
You could possibly have used something like the following idea, to define a title, your working directory, and console color all in one command:
 @Start "Statistic Portal Version: 0.1 Beta (Raport)" /D "D:\Statistic Portal" "%__AppDir__%cmd.exe" /D /T:07 /C ""D:\Statistic Portal\libraries\bin\java.exe" -Xms2G -Xmx3G -jar raportgmin.jar --server.port=9090"

Obviously you have the possibility of changing the /C option to /K to keep the window open on completion

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM