Solved

Can you dynamically program a windows task scheduler?

Posted on 2013-11-06
7
484 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

707 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

17 Experts available now in Live!

Get 1:1 Help Now