bnosac / taskscheduleR

Schedule R scripts/processes with the Windows task scheduler.
330 stars 72 forks source link

Run whether user is logged on or not #44

Closed ibombonato closed 6 years ago

ibombonato commented 6 years ago

The default setting is that the task will only run when user is logged in. Is there a way to change this setting to allow tasks to run whether user is logged on or not?

image

jwijffels commented 6 years ago

Haven't tried this but I think what you need is to pass in the argument schtasks_extra = "/IT" in taskscheduler_create See the documentation of schtasks.exe /Create /? if you run it in a shell.

jwijffels commented 6 years ago

I presume this worked for you, if not feel free to reopen.

ibombonato commented 6 years ago

Hi, sorry about the delay, but it does not work with the argument schtasks_extra = "/IT".

It worked when I passed the user and password:

schtasks_extra = "/ru username /rp password

jwijffels commented 6 years ago

Good to know!

rluech commented 6 years ago

Hi again. I continue to have issues with the Windows taskscheduler. I'm not sure if this is the right place to put the question but I don't know where else...

I need to run my tasks independent if the user is logged in or not. Neither schtasks_extra = "/IT" nor schtasks_extra = "/ru username /rp password helped, so I simply adjusted the task manually via taskschd GUI. Now the tasks run even if the user is logged off. But this had an unexpected sideffect. Now my scripts no longer connect to remote drives (e.g. I\: and P\:, but still can connect to local drive dir(C:\...) as well as to FTP server getURL(ftp://...)). Interactively I get all connections. Of course, I did not check the checkbox for "Do not store password. The task will only have access to local resources", compare printscreen above. I run the task with "Run with highest privilages". But actually I have tried all possible combinations of these checkboxes. Running on Windows 10 as user with admin rights.

Any Idea? Or hint where to get help? Taskschd seems a blackbox to me.

jwijffels commented 6 years ago

That's just because you run the script now as the admin user and no longer as your own user. If the admin user does not have all driver I\: P:\ mounted, they will not be available. So this means you need to set up your admin user to have these drives mounted and also of course all R packages should be the same as your own user if you want to be 100% sure the same is execute.

rluech commented 6 years ago

Hm. I think I understand. Set up the admin the same as my user makes things complicated. I now setup Windows to never log off my user. There sems to be the option to run taskschd as SYSTEM, is this a solution? What's the difference from System to a user or admin?

jwijffels commented 6 years ago

https://support.microsoft.com/en-us/help/120929/how-the-system-account-is-used-in-windows

MislavSag commented 6 years ago

I have tried with following code:

taskscheduler_create(taskname = "stock_forensis_task", rscript = "C:/R_code/stock_forensis_updates.R",
                     schedule = "DAILY", starttime = "15:30", startdate = format(Sys.Date() + 1, "%d/%m/%Y"),
                     schtasks_extra = '/RU "CT-VM-01\\msagovac" /RP "pass"')

but it doesn't work when I am logged off. It works if when I am looged in. I tried it on azure VM.

Do you know what can be the reason?

jwijffels commented 6 years ago

Maybe quote username and pwd differently

MislavSag commented 6 years ago

How differently? I tried with and without computer name:

'/RU "CT-VM-01\\msagovac" /RP "pass"'
'/RU "CT-VM-01/msagovac" /RP "pass"'
'/RU "msagovac" /RP "pass"'

but non of this work.

jwijffels commented 6 years ago

maybe '/RU msagovac /RP pass'

JiaxiangBU commented 5 years ago

maybe '/RU msagovac /RP pass'

It works for me.

I use /RU CORP\\lijiaxiang /RP ****** and successfully run the script both in the logging in or out.

conmaster2112 commented 4 years ago

My program runs programs but they are not Visible. Why?

arun7pulse commented 3 years ago

I am looking for a solution to this problem in the cmd line.

thekumarakshay commented 3 years ago

Hi guys, Can anyone help me how to set the checkbox of 'Run whether the user is logged on or not' to true via command prompt and that too without the password as I don't have access to user logged in password as the org uses single sign on.

dchiu911 commented 1 year ago

I tried /RU username /RP password but got this:

WARNING: The task is registered, but may fail to start. Batch logon privilege needs to be enabled for the task principal.\r"

I am also unable to edit local security policy because my user account does not have admin privileges under organizational policies. Does this mean I am unable to schedule any tasks unless I am logged on?