crribs.com

the blog of brad shultz, systems design, RETS development, ETL, scripting, and windows task scheduler stuff

Archive for the ‘Scheduled Task Management’ Category

Displaying Windows Task Scheduler Tasks with PHP

without comments

Excellent writeup of a PHP app that interfaces with the Windows Task Scheduler.  I’m going to have to double check on his use of the Task Service object.  I thought it was only COM accessible in Task Scheduler 2.0 (the new version, that comes with Vista or Windows 7, or Server 2008).  I thought in XP (which included the Task Scheduler 1.0 – the schtasks.exe or the good old Scheduled Task’s folder) that either the Task Service COM interface had to be accessed with a lower level language, or possibly the Scheduled Task’s accessible via WMI (but not through the schtask folder interface).  Its possible thats the task scheduler this code uses for access.  If thats the reality, then you may not see all the tasks you may have entered using the GUI interface, using this tool.  More on that later.
http://codesnob.wordpress.com/2009/05/18/displaying-windows-task-scheduler-tasks-with-php/

Written by bshultz

July 1st, 2010 at 2:51 pm

Send Twitter Update with VBScript

without comments

I was thinking of using Twitter as a kind of ‘syslog’ for all of the scripts we have running (via the task scheduler) all over the enterprise. There is no centralized logging implemented. Ive made some attempts via text files, sql server, the event log, etc., but nothing has taken hold as – easy to implement, universal, and straightforward. This is the visual basic script I came up with to upload the messages.



'**************************************************************************
'* Scriptname: PostToTwitterSimple.vbs
'* TWITTER STATUS UPDATE
'* Brad Shultz - crribs.com
'**************************************************************************
strUsername = "username" 'Username
strPassword = "password" 'Password
strMessage = "This is a test twitter update from a vbscript." 'Message for twitter

strTwitterXMLResponse = SendToTwitter(strMessage, strUsername, strPassword)

'postback what you sent to twitter
MsgBox strTwitterXMLResponse, VbOkOnly, "TWITTER STATUS UPDATE"

Function SendToTwitter(strMessage, strUsername, strPassword)
Set objHTTP = CreateObject("Microsoft.XMLHTTP")
objHTTP.open "POST", "http://twitter.com/statuses/update.xml", false, strUsername, strPassword
objHTTP.send "status=" & strMessage
SendToTwitter = objHTTP.responseText
Set objHTTP = nothing
End Function

Scheduled Task Report

without comments

Get a comma seperated, consolidated file with all of the configured
scheduled tasks within your domain.  Will also work in a workgroup, you
just need to be sure that you have configured a network username and
password and can authenticate successfully as an admin on that machine.
Save the following as a '.bat' file, in its own folder, along with a file named
'servers.ini'.  In th servers.ini file, simply list the machine names for those
machines you want the schtask report from.  Run it, and you should get a
text file that could be parsed through and imported into a database, or
just useful for auditing purposes.

ECHO %DATE% %TIME% > SchTaskReport.txt
FOR /F “tokens=1″ %%i in (servers.ini) DO schtasks /query /s %%i /v /fo csv >> SchTaskReport.txt

Add VBScript to Scheduled Tasks – from Context Menu

without comments

This has been something that’s bothered me for awhile- especially at work, with all the tasks I schedule daily.  It bothered me that I always had to look up the system account username and password that’d been designated as our ‘Task Scheduler Account’.  The password is a tough one (and rightly so- its a domain admin account).  It also bothered me that in order to schedule a task, I had to go to the GUI applet interface (Control Panel) or the command prompt, then add the task- even though I’d just written the script and was staring at it in the directory I wanted it to run from.  Thus was born the (fairly ugly, but useful) – ScheduleAsTask context menu item.

image

There is a limitation on the name of the vbs file- it cannot have spaces in it.  This is because we are using the filename as an argument – so if there is a space in the name, the Windows Scripting Host thinks there are multiple arguments.  This limitation could be overcome by getting the number of arguments found at runtime, and concatenating them fairly easily.

image

The default name is your script’s name, minus the extension.  If there is already a task scheduled with the same name, the script will throw an error.  You can change the task name to whatever you like in step 2.

image

And step 3 is just configuring the details for the task.

———————————————————————————

1.  Save the following code to a directory as “schtaskContextMenu.vbs” (the name doesnt matter as long as the extension is .vbs).

2.  Go to http://www.mvps.org/emorcillo/en/code/vb6/index.shtml and scroll down until you see “Using the Task Scheduler”.  Click the link underneath it and save the .dll in the same directory as the script.

3.  Run the script.  You may have to give it permission to run.  Tested on XP Pro sp2.  Might work on Vista, not sure.  Vista uses the TaskScheduler 2.0 interface, which has some backwards support.  Try it.

Here is the script zipped up for you.  Once you have the .dll from the above link in the same folder as the script, simply double click on the script.  It will ask you if you are installing or updating.  Click yes to install the whole shebang, no to just update the script (in case you make any changes), or cancel to, well, cancel the script.

Oh, and be sure to enter the account information in the .vbs so it will work on your machine (yep, its a security risk- anyone could open the script’s source and read the account info- maybe make a special non-admin account for scheduled tasks?  As far as I am concerned – in the environments I work in- the account info is available to any legit user.  If we have a rogue hacker looking through our scripts, plaintext passwords are the least of our concerns.)  Context Menu Task Scheduler Script for Vbscripts

Windows Task Scheduler Management – Scheduled Task Studio

without comments

scheduled task studio - windows scheduled task manager

scheduled task studio - windows scheduled task manager

So there arent many options out there for managing Windows Scheduled Tasks. There is the bizarre Tasks folder- a special folder in xp and server 2003 that you can access on remote machines if you have admin rights (so not on xp home edition…**arghh**). You can use the schtasks.exe command line interface…
You can spend 200 or so dollars on the Task Scheduler version of Sql Sentry (http://www.sqlsentry.net/event-manager/windows-task-scheduler-enterprise.asp – very nice program imo- especially the sql agent/task scheduler version. i used the trial version for 1 sweet month… then got my allocations request denied…).
There is Task Scheduler Pro (http://www.liebsoft.com/Task_Scheduler_Pro/)- which is 500 dollars (minimum license purchase: 5. each license costs 100 dollars… when I inquired about pricing last).
There used to be EMCO Remote Task Scheduling… But I recently noticed that it was not available anymore via the EMCO Software website (http://www.emco.is/). It had a price tag (if I remember correctly) of somewhere around 150 dollars per license.
The point is- not many options if you are on a budget and need some advanced management-ability for the windows task scheduler. The company I work for uses it and Sql Server Agent exclusively for our (extensive) job-scheduling needs.
So I’m building one. Here is the (very rough) initial layout. Ive got all the standard management capability plus visual schedule management. As soon as I verify that I can redistribute the components used, I’ll post the source. As of now, I havent gotten to remote task management (the machine is hardcoded in right now), but the goal is to be able to get a complete overview of the enterprise’s scheduled task in one view, or be able to manage individual machines, etc. Id like to add job-chaining and alerting, as well as log-aggregation. If youve ever looked at the SchedLgU.Txt (the task scheduler’s log file- c:\windows\SchedLgU.Txt – its a mess to parse through. If anyones written a comprehensive parsing regex- I’d love to look at it :) ).
More on this later.