Solved

Can you dynamically program a windows task scheduler?

Posted on 2013-11-06
7
506 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 53

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

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Compile Error 7 41
problems with mysql ODBC Connector and vbscript 4 28
Sub Reports 8 22
format date field on certain entries 8 28
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
The password reset disk is often mentioned as the best solution to deal with the lost Windows password problem. In Windows 2008, 7, Vista and XP, a password reset disk can be easily created. But besides Windows 7/Vista/XP, Windows Server 2008 and ot…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now