dahall / TaskScheduler

Provides a .NET wrapper for the Windows Task Scheduler. It aggregates the multiple versions, provides an editor and allows for localization.
MIT License
1.21k stars 191 forks source link

Where is "Startup" trigger? #895

Closed ghost closed 3 years ago

ghost commented 3 years ago

Ok, so I see there's LogonTrigger and BootTrigger. But none of them solve the use-case I'm looking to solve.

LogonTrigger - Starts when the user is logged on, but not when the computer starts after a reboot. BootTrigger - Does nothing (Starts during boot time??)

So which Trigger actually starts the program upon Startup? doesn't matter if it's a reboot or a logon, any condition that Windows starts.

dahall commented 3 years ago

BootTrigger is called one time after a system restarts. LogonTrigger is called each time a user logs in if UserId is set, or each time any user logs in if UserId is not set/null;

ghost commented 3 years ago

So now that you've explained to me those two, can you tell me where is the Startup trigger?

dahall commented 3 years ago

I believe BootTrigger is what you're looking for. The triggers supported by this library are the same as those supported by Windows, no more, no less. For further information about the triggers, please see Microsoft's documentation.

ghost commented 3 years ago

@dahall According to the documentation:

The Task Scheduler service is started when the operating system is booted, and boot trigger tasks are set to start when the Task Scheduler service starts.

Now, I'm not sure whether they're referring that the scheduler service starts at boot time or when the OS starts.

Can you explain to me why when I've used the trigger BootTrigger the startup program didn't start at any condition?

dahall commented 3 years ago

In all Windows documentation, "booted" refers to the OS. Windows services, like Task Scheduler, cannot run until the OS is available.

If BootTrigger is not working, it is likely a permission problem. You can enable Task Scheduler logging through the Task Scheduler applet in Windows and then check the Event Viewer for the errors coming from Task Scheduler when trying to run your task.

ghost commented 3 years ago

@dahall How can I disable the "only if connected to power ac" option with your library? I want to test if this is what prevented the app from starting.

dahall commented 3 years ago

https://dahall.github.io/TaskScheduler/html/P_Microsoft_Win32_TaskScheduler_TaskSettings_DisallowStartIfOnBatteries.htm

ghost commented 3 years ago

In all Windows documentation, "booted" refers to the OS. Windows services, like Task Scheduler, cannot run until the OS is available.

If BootTrigger is not working, it is likely a permission problem. You can enable Task Scheduler logging through the Task Scheduler applet in Windows and then check the Event Viewer for the errors coming from Task Scheduler when trying to run your task.

Can you redirect me to a resource where I can read more about this "permission" thing? I can barely find anything relevant on Google.

dahall commented 3 years ago
ghost commented 3 years ago

@dahall After reading a little about from the links, I think I need to enable "highest privilege". Can you tell me how to enable this in code? I can't find it in Settings.

dahall commented 3 years ago

https://dahall.github.io/TaskScheduler/html/P_Microsoft_Win32_TaskScheduler_TaskPrincipal_RunLevel.htm

TaskDefinition.Settings.Principal.RunLevel

ghost commented 3 years ago

Task Scheduler wasn't a goof fit after hours of frustrations, I went with writing to the Registry and it solved the problem. Thank you.