RickB75

Looking for a for sure way to automate Task Scheduler

8 posts in this topic

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 then

RunWait("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.

 

 

 

 

Share this post


Link to post
Share on other sites



Take a look at the Taskplaner/Taskscheduler COM UDF.  

Adam

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 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.

Share this post


Link to post
Share on other sites

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 this

RunWait("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.

 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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. 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now