The batch file is started manually, but not in the task scheduler
I have a batch file that will look for a java process and kill it. The script works fine when the bat file is run on the command line. But when I tried to execute in the task scheduler it doesn't work.
I selected the option "Run if user is logged in or not"
My batch file is below:
for /F "tokens=1*" %%i in ('jps -lv^|C:\Windows\System32\find.exe "TaskTest"') do (C:\Windows\System32\taskkill.exe /F /PID %%i )
I have also tried everything mentioned in this link The package is done manually but not in scheduled task
Any other suggestions please.
Note. I have another batch file for archiving files that work correctly in the task scheduler with the same user account
source to share
Finally, I was able to figure out the problem. It worked when I unchecked the "Start only when the computer is on" checkbox on the Conditions tab in the task properties, combined with another suggestion to use "Program" like
C:\Windows\System32\cmd.exe
and 'Add arguments' like
/c C:\mypath\myFile.bat
and "Start" as
C:\mypath\
This worked when the "Run regardless of whether the user was enabled or not" option was selected with the "Run with highest privileges" checkbox.
Thanks to everyone who takes the time to analyze this :)
source to share
Why are you looking for. Then we test, and then we don't test.
taskkill /f /im TaskTest&&Echo Task Killed||Echo Task not found
To find out what the problem is.
taskkill /f /im TaskTest > "%temp%\taskkill.log" 2>&1 &&Echo Task Killed >> "%temp%\taskkill.log" 2>&1|| Echo Task not found >> "%temp%\taskkill.log" 2>&1
and look in taskkill.log.
You can also do this in a package as a diagnostic tool. Repeating your m command line will be helpful to you.
tasklist > "%temp%\taskkill.log" 2>&1
set > "%temp%\taskkill.log" 2>&1
source to share