RickB75 Posted September 25, 2015 Posted September 25, 2015 Guys,I've been working on this for quite some time now and I am still running into issues with it. I'm sure some of you guys use Task Scheduler to run scripts at certain times of the day. In my script I use #RequireAdmin. I've tried diff ways but I can't seem to find consistent for sure way to automate the Windows Task Scheduler program.Example: This will schedule the task but it's schedules the task to run when the user is logged in only. I need the task to run whether the user is logged in or not. RunWait("SCHTASKS /Create /SC DAILY /ST 06:00 /SD 01/29/2015 /TN MyTaskName /TR " & @ScriptDir & "\MyScript.au3")I Tried using this thenRunWait("SCHTASKS /Create /SC DAILY /ST 06:00 /SD 01/29/2015 /TN MyTask /TR " & @ScriptDir & "\myScript.au3 /RU SYSTEM")This works perfect on my PC running windows 7. I have full admin access. I also have a Surface Pro with Windows 10 which I'm an admin on but I get "You don't have permissions" errors. When I set the CMD in Administrator Mode and manually insert this in the CMD Line, the task will go through Which it will then schedule it correctly to run as SYSTEM and User doesn't have to be logged in for the task to run. If I'm trying to roll out a EXE so someone cnd set up my program which Uses Task Scheduler to run the program at diff times of the day, what checks do I need to check for. I'm already checking for admin rights via #RequireAdmin. What else can I do to make sure the task get scheduled properly?? I've read in other forums that some ppl use systernials application but I don't want to use a 3rd party applicaton. Any help or advice offered is greatly appreciated.
computergroove Posted September 26, 2015 Posted September 26, 2015 #RequireAdmin RunWait("SCHTASKS /Create /SC DAILY /ST 06:00 /SD 01/29/2015 /TN MyTask /TR " & @ScriptDir & "\myScript.au3 /RU SYSTEM") Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html
AdamUL Posted September 26, 2015 Posted September 26, 2015 Take a look at the Taskplaner/Taskscheduler COM UDF. Adam
jdelaney Posted September 26, 2015 Posted September 26, 2015 (edited) Running as admin has nothing to do with creating a scheduled task. All that matters are the credentials you provide, and the setting to state you want to run as administrator. Of course, those credentials must have the rights to run as such. Specifically the /ru and /rp.After that, you can initiate the task without admin rights, but execute the task as if you were in an admin command prompt. Edited September 26, 2015 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
RickB75 Posted September 26, 2015 Author Posted September 26, 2015 I've been testing this out on my Surface Pro because that machine gives me the most issues. I still can't schedule a task as the SYSTEM account using thisRunWait("SCHTASKS /Create /SC DAILY /ST 06:00 /SD 01/29/2015 /TN MyTask /TR " & @ScriptDir & "\myScript.au3 /RU SYSTEM")When I check for the task, it simply doesn't exist. I really wish I could get this to work consistently this way mainly because running as the SYSTEM account, everything will run completely in the background.When I use this RunWait("SCHTASKS /Create /SC DAILY /ST 04:00 /TN VSpecUpdate /RU MyUserName /RP myPassword /TR " & @ScriptDir & "\Update.exe" )It does schedule the task to run whether I'm logged in or not which essentially is kinda what I'm looking for. I still don't know if it will run my main exe completely in the background though. With my main exe, at install, I create Start Menu shortcuts so the user can manually run the program if they want to. To show the user the program is running I have progress bars that appear. When the System account runs the program from the task scheduler, everything runs completely in the background. Do you guys know if I schedule the task to run as the user, will the task run in the Background even if the user is logged on the machine or will they see the progress bars when the program runs when started by the task scheduler. How common is it to ask the person installing the program for their windows login password? Basically at install, I would need to prompt the user for their windows login password as the installer checks to see if they have admins rights.
jdelaney Posted September 26, 2015 Posted September 26, 2015 Scheduled tasks do run in the background...unless you specify to use the desktop, and even then, the scheduled task must be set for the user of the desktop.Google it, read up on it. IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
RickB75 Posted September 26, 2015 Author Posted September 26, 2015 In your opinion would I be out of line asking for the person's Windows Login password? The reason I ask is because I have a close friend who say's I shouldn't ask for it and that I should research another way to schedule the task. WMI maybe.
drummerdp Posted June 28, 2016 Posted June 28, 2016 Hi Rick, I struggled with this for quite a while and finally came up with this method. Must be run as admin, but does not ask for a password. It's a hybrid that uses AutoIt code to front end and call a PowerShell script that updates the Windows scheduler. This code has worked flawlessly for me during daily runs for the past month. Programs call it when scheduling my morning run each day for different times depending on various factors. Here's the skeleton code, which I'm sure you can customize to your needs. Hope you have the same success I have. Note: You will need to set AutoIt variable $aspowershellpath to the directory where you place the MySched.ps1 PowerShell script - Dave AutoSched.Au3 MySched.ps1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now