1

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 here enter image description here enter image description here

  • Is savbuildsvc the user that is actively logged on to the computer, meaning that is the active console session? – Appleoddity Jan 13 '18 at 2:22
  • @Appleoddity yes. Basically, this account used to service, maintain, run, etc. This is because this is production server and this account has full access to the resources to which other people have only read access. And there are few other reasons – T.S. Jan 13 '18 at 16:35
  • 1
    @ITSnuggles Thank you. I will evaluate and test. And will let you know. – T.S. Jan 13 '18 at 21:16
  • 1
    @PimpJuiceIT I was sidelined with something else. Need to get back to it. Will [eventually] let you know, etc – T.S. Jan 24 '18 at 0:21
  • 1
    @PimpJuiceIT Hey, I am very sorry. Bad news first: 1-item lost its priority completely due to less users of build server. 2-I had family issues and was away, working part time. 3-because of #2 I am swamped to the gills and even not active at all on SOF or SU. Good news is that because our team was reduced, our build automation right now is in "pimp mode". + my boss is not going to be around next week so nobody will be asking why I spent time for "things" destined to back burner. So, I probably can give it a shot next week. Thank you for your patience – T.S. Jul 26 '18 at 5:10
1

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.

  • This is fair. But, here is another variable... While this is true that this user is nearly permanently logged on, there are instances when it is not. For example, when server reboots after update. But I definitely need task to run even if user is not logged on. I also see that you have "Configure for" Vista and Win serv 2008. Does it make difference? Thanks – T.S. Jan 13 '18 at 16:39
  • @T.S. No that won't make a difference but use Windows Server 2016 in your case. I will give you an update once I test something out here now that you told me about this variable thing.... There is still a doable solution that I will provide here shortly after I test and confirm it works as I'm thinking. – Pimp Juice IT Jan 13 '18 at 17:39
0

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 here enter image description here enter 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

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.