14

I'm running Windows 10, and trying to get a pair of scheduled tasks working. These tasks are set to run on workstation lock and workstation unlock, and execute a script that remotely locks or unlocks an adjacent arch-linux workstation. This is accomplished via the WinSCP command-line interface, WinSCP.com, and its built-in scripting ability. These scrips are working just fine - I can invoke them manually to the desired effect. I can even right-click the tasks I've set up and click 'run', and observe the desired effect. The problem is that the workstation-lock and workstation-unlock events don't appear to ever be triggered, when actually locking and unlocking the workstation. This same set of scheduled tasks worked as expected under Windows 7.

Lock/Unlock tasks overview

Task Scheduler window

Based on answers so far, I can get the tasks to run as expected if I check the "Run only when user is logged on" box, but this has the undesired side effect of causing a visible command window to appear when the tasks are triggered.

OS is Windows 10 Enterprise LTSB 2016 (x64). Any insight or ideas would be appreciated.

Things I have already tried:

  • Using GPO to enable auditing of workstation lock/unlock events - no effect. (lock/unlock events appear in the event viewer as expected)

  • Creating an alternate windows user and setting the task to run as that principal.

  • Wrapping the call to WinSCP.com in a batch script.

  • Modifying local GPO to ensure that logon-as-batch is enabled.

Other relevant information: Other scheduled tasks (e.g. those running at a set time or interval) are working fine. Only these two tasks are failing to trigger.

Edit: Per Twisty's comment, I turned on task history, and got an actual error message: Task scheduler error message

So it appears the task is indeed triggered, but fails to launch. Interestingly, this does not update the "Last Run Time" property for the task.

Some cursory googling indicates that this error may be related to logon/password information. I've verified that the stored password is correct, but the same issue persists. Here is a screenshot of the 'General' tab as requested.General Tab

Here is the WINSCP script being executed (key censored):

# Connect
open sftp://charles@192.168.0.1:2222/ -hostkey="ssh-rsa 2048 
xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
call cinnamon-screensaver-command -d
close
exit

I've just tried wrapping this in a very simple batch file:

@ECHO ON

SET prgwinscp="C:\Program Files (x86)\WinSCP\WinSCP.com"
%prgwinscp% /script=lock-arch.winscp

I can execute this by hand, and as a scheduled task it works when I check "Run only when user is logged on". Unfortunately, as before, once I set the task to "Run whether user is logged on or not", I get the usual failure.

As requested, here is a screenshot of the actions tab:actions pane

The obscured text is as follows:

Add Arguments (Optional):    /script=unlock-arch.winscp
Start in (Optional):    C:\Program Files (x86)\WinSCP
Fopedush
  • 1,889
  • @Twisty Updated question with additional information per your comments. – Fopedush Jun 07 '17 at 18:19
  • @Twisty it appears that switching to "run only when user is logged on" alleviates the issue, but has the unfortunate side effect of causing a cmd window to appear on my desktop (see https://www.howtogeek.com/tips/how-to-run-a-scheduled-task-without-a-command-window-appearing/). I'd much rather be able to keep the window hidden, if possible. – Fopedush Jun 07 '17 at 18:23
  • Is Charles the currently logged on user, or no? – I say Reinstate Monica Jun 07 '17 at 18:59
  • yes - Charles is indeed currently logged in. – Fopedush Jun 07 '17 at 19:04
  • To prevent this command window from appearing, create another user account with the necessary permissions to successfully run the task, then configure the task to use that user's credentials. 2) The error code you're getting suggests either the password for the account is wrong, or that you need to enable the option "if task is already running, stop existing instance" on the Settings tab.
  • – I say Reinstate Monica Jun 08 '17 at 00:19
  • @Fopedush I'm having the exact same issue with a .bat script. Timed tasks run fine, but lock/unlock triggers always fail. I've tried all the suggestions in the answer to no avail. Did you ever get this resolved? – Waxen Sep 06 '17 at 19:01
  • I managed somehow to lose administrative privileges on my home PC, so I couldn't run certain half-hour tasks regularly. The solution was just to restart the computer. But this question also spurred me to look into options I didn't know were there, so thanks! – aschultz Apr 27 '21 at 16:47