Workaround for scheduled task on Windows requires user to log in

I am running a small executable file created by a third party that should run regularly on a Windows 2008 server. This executable file efficiently uses ETL information from one system to another and should work every hour or so around the clock. As part of its processing, the executable file launches the small Windows Forms user interface.

I set a scheduled task to call the file, and this works ONLY if the user under whom the task is configured to run logs on to the computer (locally or via remote desktop). If I set the task to run as another user or set the task to run when the user was not registered, the scheduled task execution and errors. I tried to work as different users, including the admin user and the system user. Are there any possible workarounds (without changing the third-party code, to which I do not have access), which would allow this code to be run without the participation of a specific user.

+10
source share
7 answers

The GUI application requires a desktop, and you get only one of them for a registered user.

+4
source

This article shows how to create a task that does not require an entry: https://www.scriptjunkie.us/2013/01/running-code-from-a-non-elevated-account-at-any-time/

The described procedure is as follows:

First, create a scheduled task to run your team with default settings as the current user (this will by default create a scheduled task that runs only when you log in):

schtasks /create /tn mytask /SC HOURLY /TR "calc"

Then export the task as XML:

schtasks /query /XML /tn mytask > temp.xml

and delete the task:

schtasks /delete /tn mytask /f

Then open the xml file and replace the line <LogonType>InteractiveToken</LogonType> with <LogonType>S4U</LogonType>

This can be done using the following commands assuming powershell is on the system: powershell -Command "Get-Content '.\temp.xml' | foreach {$_ -replace 'InteractiveToken', 'S4U' }" > new.xml move /y new.xml temp.xml

Now recreate the task from the modified XML file:

schtasks /create /xml temp.xml /tn mytasks

and delete the temporary file:

del /f /q temp.xml

+4
source

Maybe I was late for an answer, but we cannot use the command without / interactive ...

https://support.microsoft.com/en-us/kb/313565

According to microsoft: / interactive: use this option to allow the task to interact with the desktop of the user who is logged in during the execution of the task.

+3
source

I think I found a solution for this situation. You need to have two accounts on the server (User1 and User2). RMD to the server under User1. As part of this RMD, create a scheduled task and set it to run under the User2 account. Then, from within this RMD, you need RMD in the server itself using the credentials of User2 (sort of like dream dreams in a dream). It is important not to minimize this new RMD window; you can make it small, but it must be open. You can then close the original RMD session and the task will be started under the User2 account, since User2 has an open desktop from the second RMD session.

Protip - do not disconnect the handles of the RMD window at the top of the RMD window - then it can be painful to close the correct RMD. If you do this, you will need to use the "Start"> "Exit" option completely from your RMD.

+2
source

There is a simple solution. Change the group to the "users" of the local group and you will not be asked to enter a password. (Scheduled task - General - Security settings - Change user or group).

+2
source

It would seem that from my research (and the answer of David Heffernan), without affecting the source code, this is impossible.

There are some useful thoughts on How can I run a Windows GUI application as a service? that relate to this, but none of them provide a viable solution to this problem.

+1
source

It looks like an old thread, but I recently ran into this in my organization due to UAC requirements that they did not use. I am still testing this, but I believe that you can still enable interactive mode for a scheduled task by using the /Change command in the task and adding the /IT flag to make it interactive. Link here: https://docs.microsoft.com/en-us/windows/desktop/taskschd/schtasks

 schtasks /Change /tn "Task A" /IT /RP "password of user if used" 

My initial tests show that this works, but I don’t see a noticeable difference with the task in the task scheduler when I do this. So I'm not sure how to check if it is installed for this.

0
source

Source: https://habr.com/ru/post/894267/


All Articles