Solved

Can you dynamically program a windows task scheduler?

Posted on 2013-11-06
7
536 Views
Last Modified: 2013-12-18
My workgroup has a series of Access macros/reports that run each day with the help of windows task scheduler. Most of the files being imported each day maintain the same name.

Is there a way to program the scheduler to run when the Date Modified property is updated?
0
Comment
Question by:Dominator1025
7 Comments
 
LVL 14

Expert Comment

by:Bill Ross
ID: 39629926
Hi,

I would write a DOS batch file that checks the file date and runs access /macros if the file date is changed.  It will take some research but you can use an if statement.

Run the batch file each hour or whatever using the event scheduler.

Regards,

Bill
0
 
LVL 26

Expert Comment

by:Nick67
ID: 39630911
Is there a way to program the scheduler to run when the Date Modified property is updated

Not per se.
The scheduler runs on a time basis, period.
Now, a VBScript that checks the files you have in mind, checks to see if Access is open, and if the files have changed and Access is not running, fires up Access to do the rest could be written.  It then can be scheduled to run very frequently.

But the task scheduler itself, that gets set off strictly by a time event.
0
 
LVL 3

Expert Comment

by:0Doc
ID: 39631037
Create a VB script that that checks if files have been modified.  In the script, if a modified file is detected, then launch the task scheduler.  This can be done with the SCHTASKS command.  Something like SCHTASKS /Run /TN <my scheduled tasks>.

I hope this helps,

0doc
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
LVL 54

Expert Comment

by:McKnife
ID: 39631877
@Nick67
> The scheduler runs on a time basis, period.
That's wrong. Starting with windows xp we could trigger tasks on event creation. With Vista/7/8/8.1 this is even GUI driven possible (with xp there was eventtriggers.exe).

That said: you could setup ntfs auditing on that file. Whenever it gets changed, an event would get created in the security event log and that event can be attached to your task.
0
 
LVL 14

Expert Comment

by:Bill Ross
ID: 39631896
Hi,

Back to my original comments - use the task scheduler to run the test process at an interval, say hourly,  and execute if file date is updated.  Process can be any scripting language.

Regards,

Bill
0
 
LVL 26

Expert Comment

by:Nick67
ID: 39631916
Options
Neat enough.  Here are the full list of things that can set off a task in Win 7.
Perhaps the only fly in the ointment of doing it through auditing and the event log is that the Access process may also trip the auditing and set off the task again.  But then, that depends very much upon other options (don't run this task if it is already running) and what code you make the task do.

But @McKnife, you were right, time isn't the only trigger by a long shot.
Thanks,

Nick67
0
 
LVL 25

Accepted Solution

by:
SStory earned 500 total points
ID: 39633328
You could forget the scheduler and write a VB.NET app or service that will have a FileSystemWatcher. It could watch for file changes and evaluate them.

Here is an example from MSDN

    ' Create a new FileSystemWatcher and set its properties. 
        Dim watcher As New FileSystemWatcher()
        watcher.Path = args(1)
        ' Watch for changes in LastAccess and LastWrite times, and 
        ' the renaming of files or directories. 
        watcher.NotifyFilter = (NotifyFilters.LastAccess Or NotifyFilters.LastWrite Or NotifyFilters.FileName Or NotifyFilters.DirectoryName)
        ' Only watch text files.
        watcher.Filter = "*.txt" 

        ' Add event handlers. 
        AddHandler watcher.Changed, AddressOf OnChanged
        AddHandler watcher.Created, AddressOf OnChanged
        AddHandler watcher.Deleted, AddressOf OnChanged
        AddHandler watcher.Renamed, AddressOf OnRenamed

        ' Begin watching.
        watcher.EnableRaisingEvents = True

Open in new window

(source: http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx)

Here is another example of using it:
http://www.codeproject.com/Articles/3192/Watching-Folder-Activity-in-VB-NET

You could get enough info from these two to build it.  The one from MSDN appears to do exactly what you want and more.  Then you'd just leave that program or better service always running to take care of this.

The following shows you how to create a Windows service:
http://msdn.microsoft.com/en-us/library/zt39148a%28v=vs.110%29.aspx

Just remember that it can have no user interaction.
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
randomize data from excell cell 15 46
Trying to filter a sub-report 9 31
Use after update to change dates 2 16
Add Attendee Macro need not halt for Acknowledgement 12 23
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question