cmd scheduled task doesn't launch my program at startup

0

I need to SCHTASKS to launch an exe with administrator privileges when I log in. So I tried this code on CMD:

schtasks /Create /SC ONLOGON /TN Scheduled /TR "C:\Users\myuser\Desktop\my folder\myprogram.exe" /RL HIGHEST

It create the task, but when I login with my user, myprogram.exe is not launched.

I have to create scheduled task through command line because I have to create scheduled task with Pyton

secon25

Posted 2019-02-16T13:28:23.073

Reputation: 1

Onlogon is not onstart. There are multiple issues here. If the task runs as the user it will NOT be with administrator privileges unless the user is an administrator. In addition, a task that runs at startup can not run as the logged on user - because one isn’t logged on. Finally, you’re referencing a script saved in a user profile. ONLY a script running as that user is going to be able to access that file. Regardless of administrator access or not. If you truly want the script to run at startup, then run it as SYSTEM and put the file in a common area like C:\ProgramData. – Appleoddity – 2019-02-16T16:05:16.060

If you want the task to run when a user logs on, then [edit] and clarify your question. You said “at startup,” and “when I start windows.” Additionally, provide any error message task scheduler shows for the task when you run it. – Appleoddity – 2019-02-16T16:09:58.117

There are differences in Task Scheduler behavior in different versions of Windows, so please include the OS detail. Is there a reason you chose to create this with a command rather than using the GUI? Also to run with Admin rights the account MUST have a password. – Debra – 2019-02-16T23:33:17.557

Thank you all for the answers and sorry for my late answer. Anyway, if i put the file in C:\ProgramData it works. so: schtasks /Create /SC ONLOGON /TN Scheduled /TR "C:\ProgramData\my folder\myprogram.exe" /RL HIGHEST will works. But It is very slow. I mean, when i turn on my pc, myprogram.exe will start, but it needs about 2 minutes to works. Is my pc the problem or i'm wrong something when i create the scheduled? – secon25 – 2019-02-18T11:38:29.350

@Appleoddity I edited, sorry I was confused about difference between on start and on logon, anyway I understood it now. If you post the answer, i can accept your answer. – secon25 – 2019-02-18T11:56:37.157

@Debra I'm using Windows 10. My accounts has password. I solved the problem, thanks anyway – secon25 – 2019-02-18T11:57:19.657

No answers