vba to populate windows task manager (1 Viewer)

CJ_London

Super Moderator
Staff member
Local time
Today, 09:47
Joined
Feb 19, 2013
Messages
16,607
Hi,

I have asked a similar question before but now can't find the thread - I think it was a follow on from a thread started by someone else.

To summarise, I have my own scheduler to schedule tasks like reminders, running and email reports etc. Problem is if Access is not open, it doesn't run. So the suggestion was to migrate these to the windows task manager. This I have done.

However users are not particularly savvy about using the task manager and when to use it so I thought it would be a better idea to take the data from my scheduler and use VBA to 'upload' a new task in the windows task manager, either on the user machine or the server or an 'always on' spare machine.

I can do this manually using schTask in the command box with all the relevant flags, but can't seem to get it to work using vba - for example I'm using the following to list what is in the task manager at the moment

Code:
 dim rtn as variant
  
 rtn=shell("schtasks /Query /FO csv")
 debug.print rtn
but all I get is a number, not sure if it is an error code, but I get different numbers each time I run it so probably not.

Any thoughts?
 

vbaInet

AWF VIP
Local time
Today, 09:47
Joined
Jan 22, 2010
Messages
26,374
Hey CJ, the return value is the process ID.

If you want to see the command prompt window after the command executes you can do:
Code:
shell "cmd [COLOR="blue"]/k[/COLOR] schtasks /Query /FO csv"

You would most likely want to retrieve the results so I would advise something like this:
Code:
shell "cmd [COLOR="Blue"]/c[/COLOR] schtasks /Query /FO csv > %TEMP%\tasklist.txt"
...output it to a text file in the temp folder and manipulate the contents of the file using the fso. Or you could pipe the results of the query to findstr, filter the results, output to a temp file then read the results from the file.

Perhaps you could grab some bits off this snippet of code:
http://www.access-programmers.co.uk/forums/showpost.php?p=1429150&postcount=12

By the way, don't you think that by making it so easy, your users may abuse the use of task scheduling?

Fyi, if you're interested in code that will open the task scheduler interface, then here:
Code:
shell "cmd /c Taskschd.msc"
 

CJ_London

Super Moderator
Staff member
Local time
Today, 09:47
Joined
Feb 19, 2013
Messages
16,607
Thanks vbIbnet

Just hadn't taken the code far enough!

By the way, don't you think that by making it so easy, your users may abuse the use of task scheduling?
Possibly, this is intended as an extended functionality to the existing process - my current schedule setup form already stores the current username (which they can change to another user) so only that user will trigger that particular schedule when they are running access. (otherwise in a multi user environment, each user would be triggering the same schedule). I would modify it so that it asks if the schedule is 'time critical' and if so could then 'move' it to task manager. If it proves a problem, I can limit each user to one or two time critical schedules.
 

vbaInet

AWF VIP
Local time
Today, 09:47
Joined
Jan 22, 2010
Messages
26,374
Sounds like a useful little app. Good luck with it!
 

Users who are viewing this thread

Top Bottom