I've created a batch file (EnableDisable.bat) that will disable a Windows Task Scheduler job (SampleJob) on a local system, if a job with same name (SampleJob) is already enabled and running on another remote system.
It seems that when the job is setup with the Run whether user is logged on or not option checked along with Run with Highest privileges that it just doesn't work and the reason is hard to determine and I'm not sure how to troubleshoot.
Batch File
for /f "tokens=1" %%j in ('schtasks /Query /S [servername] /TN "SampleJob" /NH ^| findstr "Ready ^| Running"') do schtasks /Change /Disable /TN "%%j"
Note: The remote system is referred to as [
servername] and will be replaced by the actual remote server name where needed.
Windows Task Scheduler Job Configurations
- This batch file is configured as a Windows Task Scheduler job
- Name:
EnableDisableJob - Security Option:
Run whether user is logged on or notRun with Highest privileges
- Name:
Observations
If I run the job with the Run only when user is logged on it seems to work just fine without any issue. However, it seems like when I try to run it with the other option, and because that account is not logged on, it cannot run when that is the case.
Question
How do I troubleshoot this sort of issue and where should I start to begin that process?