Velvet Star Monitor

Standout celebrity highlights with iconic style.

news

Make executing CMD window show when it is ran by a task scheduler

Writer Sophia Terry

I have task that runs on windows server 2016. The user account under which task runs is always logged on. When task runs, it kicks FBCMD.exe which is FinalBuilder program that executes some parameters. When I start this program via batch file, I see the window. But when task scheduler starts this program using exact same parameters, it runs on background. I want this window to show. In fact, when we ran this in win7 it did show. Here are images of the task setup. Can this be done?

enter image description hereenter image description hereenter image description here

8

2 Answers

Run a Scheduled Task Interactively

Simply check the Run only when user is logged on from the General tab and Security options section to ensure the process is run visibly/interactively with the logged on session.

Since you say "The user account under which the task runs is always logged on" and the expected result is for the screen to be visible when the Task Scheduler job executes the process, then you only need to make that simple adjustment to get the expected result.

enter image description here


Further Resources

  • Task Security Context

    • To make a task run interactively, select the Run only when user is logged on radio button.

2

Conditionally Run a Scheduled Task Interactively or Not

If you have a need to conditionally run a scheduled task interactively with Task Scheduler if a particular user account is logged onto a system or else run it non-interactively then I will outline some steps to get you the expected result based on some conditional logic and with a batch script.

Essentially this solution will require a few simple things. . .

  1. Define a scheduled task to run interactively with the Run only when user is logged on option selected to run if the user account is logged on with no triggers defined
  2. Define another scheduled to run non-interactively with the Run whether user is logged on or not option selected to run if the user account is not logged on with no triggers defined
  3. Create a batch script (example below) that will check if the user account is logged on or not and based on the result execute either the interactive or non-the interactive scheduled task
  4. Define another scheduled to run non-interactively with the Run whether user is logged on or not option selected to run if the user account is not logged on with triggers defined for the frequency you need the jobs to run regardless if interactive or not—so this will be the scheduled job that executes either of the two other jobs from #1 or #2 above.

Batch Script

This uses query-session and findstr to check whether or not the applicable username is signed onto the machine console. It then uses schtasks to execute either the interactive or non-interactive scheduled tasks that you define without any triggers.

You will want to change the SET username= value to be what you need it to check for account name wise which you need it to run interactively with that session if it exists (e.g. <Domain>\<Username>)

@ECHO OFF
SET username=user
query session | findstr /I /M "%username%" | findstr /I /M "console"
IF ERRORLEVEL 0 GOTO :InteractiveTask
GOTO :NonInteractiveTask
:InteractiveTask
SCHTASKS /Run /TN "\_SuperUserTesting\FinalBuilder_i"
EXIT
:NonInteractiveTask
SCHTASKS /Run /TN "\_SuperUserTesting\FinalBuilder_n"
EXIT

Important: You will need to ensure the location and task name full path is specified with the /TN switch of the schtasks commands to point to the correct task and path location the per hierarchical structure where you saved each with Task Scheduler—see below to screen shots to further clarify. enter image description hereenter image description hereenter image description here

Furthermore, you will need to ensure the Allow task to be run on demand is set from the Settings tab of each scheduled task which will be executed with schtasks.

enter image description here


Scheduled Tasks

The interactive scheduled task must have the Run only when user is logged on option checked from the General tab in order for it to be run interactively.

enter image description here

The non-interactively task must have the Run whether user is logged on or not option checked from the General tab in order for it to be run if that account is not logged onto the machine.

enter image description here

The task that checks to determine which scheduled task to run with the batch script must have the Run whether user is logged on or not option checked from the General tab in order for it to be run regardless. Other than that, you can setup the Triggers with whatever schedule you desire.

enter image description here


Further Resources

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy