Jump to content

Scheduling an interactive task in AutoIt - (Moved)


Go to solution Solved by scifigeek64,

Recommended Posts

Forgive me if this is a stupid question, but I haven't programmed in 15 years and I have forgotten more than I remember about AutoIt. I have a Script that needs to be scheduled to run interactively. It is going to open a web browser, click on a few things, close the browser, then schedule itself to run again the next day, 2 minutes later than it just ran. I can't for the life of me get it to run the task from the Task Scheduler.  It will sometimes start Firefox, but it never runs it interactively, so it never actually does anything. It also doesn't seem to have permission to update the schedule to the next day.

This is the line in question...

RunWait('schtasks /change  /tn ScheduledScript /SD $Schdate /ST $Schtime /RL Highest /IT /TR "c:\users\xxxxx\desktop\apps\AutoitScript.exe"')

$Schdate and $SchTime are obviously variables with the date and time to run next. If I manually run the script, it does what it is supposed to do until this line when it tells me that I don't have the right permission. (I'm the only user of the PC and have Administrative rights.) I know this isn't much to go on, but does anyone have any ideas?

Thanks,

Mike

Link to comment
Share on other sites

  • Moderators

Moved to the appropriate forum.

Moderation Team

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Is the user logged in at the time the scheduled task is triggered? From the help:
 

Quote

/IT                     Enables the task to run interactively only if the
                         /RU user is currently logged on at the time the job
                         runs. This task runs only if the user is logged in.

 

Link to comment
Share on other sites

I re-read your post and I think I missed something the first time. If you're getting a permissions error, your script needs 

#requireadmin

I create/edit scheduled task kind of a lot but I tend to make edits as the system user so I have to shift gears a little when thinking about how other people use it 😅

You may need to post minimum viable code (ex, directives) if the above doesn't work.

Link to comment
Share on other sites

Posted (edited)

I thought it was working in my new method but it isn't. This is my new code:

RunWait('Schtasks /delete /tn Scriptfile /f')
RunWait('schtasks /create  /sc daily /TN Scriptfile /SD $schdate /ST $schtime /RL HIGHEST /IT /TR c:\users\xxxxx\desktop\apps\Scriptfile.exe')

 

It deletes the task from the scheduler, but the new task is not created. I have verified that the variables are correct and I had to tell Windows Anti-viirus that it was safe to run files from this directory, but it won't create the new schedule entry.  I have tried it from a 2 line script like this:

#requireadmin
RunWait('schtasks /create  /sc daily /TN Scriptfile /SD 08/13/2024 /ST 12:01:00 /RL HIGHEST /IT /TR c:\users\xxxxx\desktop\apps\Scriptfile.exe')

If I just run it, it works fine and Scriptfile will run at the time that I specify, but it deletes the scheduled task and no new one is created.

Any more ideas?

Edited by scifigeek64
Link to comment
Share on other sites

So I used you two liner (#requireadmin and the runwait but different exe so it could create a valid task) and it ran with no errors and created the scheduled task. However, I couldn't see the task unless I ran the Task scheduler GUI elevated. See attached:

Regular user (non-elevated) on the left. "Run as Administrator" (elevated) on the right.image.thumb.png.b0ac6d5a50ed1cf0b5eec60f502ea12e.png

You can see there's more tasks that are invisible (19 additional!) to the non-elevated account. So I can only assume that something is broken with the line with variable-ized values.

Edited by rsn
Link to comment
Share on other sites

When you post code, even if it minimal, please use the method shown in the link.

By posting one line at a time, it is not helping us one bit.  You should post a runable script that we can use as a startup.  So you have more chance of getting help...

Link to comment
Share on other sites

4 hours ago, Nine said:

When you post code, even if it minimal, please use the method shown in the link.

By posting one line at a time, it is not helping us one bit.  You should post a runable script that we can use as a startup.  So you have more chance of getting help...

Got it. Thanks.

 

Link to comment
Share on other sites

  • Solution

I found the issue. It was all about syntax. I needed to have my variables outside of the single quote for the schtasks. This is what I needed:

RunWait("schtasks /create  /sc once /TN Scriptfile /SD " & $schdate & " /ST " & $schtime & " /RL HIGHEST /IT /TR c:\users\xxxxx\desktop\apps\Scriptfile.exe")

It was really stupid on my part, but at least I finally figured it out. Thanks for the help.

Mike

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...