Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
720 views
in Technique[技术] by (71.8m points)

java - Batch File runs manually but not in task scheduler

I have a batch file, which will search for a java process and kill the same. The script works fine when the bat file is run on the command prompt. But when I tried to execute in task scheduler, it is not working.

I have selected the option "Run whether the user is logged in or not"

My batch file is as given below:

for /F "tokens=1*" %%i in ('jps -lv^|C:WindowsSystem32find.exe "TaskTest"') do (C:WindowsSystem32askkill.exe /F /PID %%i )

I have also tried whatever is mentioned in this link Batch runs manually but not in scheduled task

Any other suggestions please.

Note: I have another batch file to archive files which runs properly in task scheduler with the same user account

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Finally I was able to figure out the problem. It worked when I unchecked the option "Start only when the computer is on AC power' under 'Conditions' tab in task properties, combined with the other suggestion of using the 'Program' as

C:WindowsSystem32cmd.exe

and 'Add Arguments' as

/c C:mypathmyFile.bat

and 'Start in' as

C:mypath

This worked when the option 'Run whether user is logged in or not' is selected with 'Run with highest privileges' checked.

Thanks for all those who have spend time to analyse this :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...