Page 1 of 1 1
Topic Options
#111549 - 2004-01-09 02:11 PM Strange behavior of Task Scheduling tools...
Co Offline
MM club member
***

Registered: 2000-11-20
Posts: 1341
Loc: NL
FYI,

I wanted to enumerate scheduled tasks on remote computers.

With some help of Shane and Jens I created a script which i can use to schedule a task on multiple computers:
ScheduleTask - Array problem

In this script I use Scheduletask(). Since JT.exe is required for this UDF I thought JT must do the job but it fails...
Quote:


C:\>jt /sm comp1 /se
[TRACE] Setting target computer to 'comp1'
[TRACE] Enumerating jobs and queues
[FAIL ] IEnumJobs::Next hr=0x80070003




..so I created this script and have used it on a WinXP PC:
Code:

Break on
If $strComputer = ""
$strComputer = "."
EndIf


$objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" + $strComputer + "\root\cimv2")
If $objWMIService
$colScheduledJobs = $objWMIService.ExecQuery("Select * from Win32_ScheduledJob") ; ,,48)

For Each $objItem In $colScheduledJobs
$name=$objItem.name
$command=$objItem.Command
$days=$objItem.DaysOfWeek
$mstime=$objItem.StartTime
$ro=RedirectOutput("d:\log\"+@WKSTA+".log",0)
? 'task: '+$name+Chr(9)+$command+Chr(9)+$day+Chr(9)+$mstime+Chr(13)+Chr(10)
If $strComputer = "."
$strComputer = @wksta
EndIf

Next

;sleep 10
EndIf



It works but it only shows tasks scheduled by AT and it doesn't show tasks that are scheduled by JT.exe, Schtasks or the Scheduled Tasks GUI. It must be a WMI / Win32_ScheduledJob problem because the following VBscript gives the same output:

Code:
 strComputer = "."

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colScheduledJobs = objWMIService.ExecQuery _
("Select * from Win32_ScheduledJob")
For Each objJob in colScheduledJobs
Wscript.Echo "Caption: " & objJob.Caption
Wscript.Echo "Command: " & objJob.Command
Wscript.Echo "Days Of Month: " & objJob.DaysOfMonth
Wscript.Echo "Days Of Week: " & objJob.DaysOfWeek
Wscript.Echo "Description: " & objJob.Description
Wscript.Echo "Elapsed Time: " & objJob.ElapsedTime
Wscript.Echo "Install Date: " & objJob.InstallDate
Wscript.Echo "Interact with Desktop: " & objJob.InteractWithDesktop
Wscript.Echo "Job ID: " & objJob.JobID
Wscript.Echo "Job Status: " & objJob.JobStatus
Wscript.Echo "Name: " & objJob.Name
Wscript.Echo "Notify: " & objJob.Notify
Wscript.Echo "Owner: " & objJob.Owner
Wscript.Echo "Priority: " & objJob.Priority
Wscript.Echo "Run Repeatedly: " & objJob.RunRepeatedly
Wscript.Echo "Start Time: " & objJob.StartTime
Wscript.Echo "Status: " & objJob.Status
Wscript.Echo "Time Submitted: " & objJob.TimeSubmitted
Wscript.Echo "Until Time: " & objJob.UntilTime
Next


Quote:


Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

Caption:
Command: Notepad.exe
Days Of Month:
Days Of Week: 21
Description:
Elapsed Time:
Install Date:
Interact with Desktop: True
Job ID: 1
Job Status: Success
Name:
Notify:
Owner:
Priority:
Run Repeatedly: True
Start Time: ********213000.000000+060
Status:
Time Submitted:
Until Time:
Caption:
Command: notepad
Days Of Month:
Days Of Week:
Description:
Elapsed Time:
Install Date:
Interact with Desktop: False
Job ID: 3
Job Status: Success
Name:
Notify:
Owner:
Priority:
Run Repeatedly: False
Start Time: ********170000.000000+060
Status:
Time Submitted:
Until Time:
Exit code: 0 , 0000h






The only tool wich gives all tasks and works on remote pc's is the XP schtasks command. unfortunately you cann't use it with previous versions of Windows

D:\>schtasks /query /S comp2

TaskName Next Run Time Status
==================================== ======================== ===============
test 17:00:00, 9-1-2003


Maybe it is an easy problem and did I used the wrong JT parameters..


Edited by Co (2004-01-09 03:14 PM)
_________________________
Co


Top
#111550 - 2004-01-09 04:13 PM Re: Strange behavior of Task Scheduling tools...
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
I have a version of schtasks.exe that works with Win2k. If you are interested, reply with your email address.
Top
#111551 - 2004-01-09 04:17 PM Re: Strange behavior of Task Scheduling tools...
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
Which is a byte-hacked version of the Windows XP version as detailed in http://www.jsiinc.com/SUBK/tip5300/rh5335.htm

However, the advantage of JT.EXE is that it works under any Windows that has the Task Scheduler installed and we already have a complete set of UDFs to manage scheduled tasks either via the ScheduleTask() UDF for simple schedules or the tsControl() UDF collection for advanced task scheduling.


Edited by sealeopard (2004-01-09 04:21 PM)
_________________________
There are two types of vessels, submarines and targets.

Top
#111552 - 2004-01-09 04:20 PM Re: Strange behavior of Task Scheduling tools...
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
Quote:

It works but it only shows tasks scheduled by AT and it doesn't show tasks that are scheduled by JT.exe,


This is by design and well documented on MSDN. The WMI object can only interact with AT-type tasks but not task scheduled otherwise, e.g. via Task Scheudler or JT.EXE.
_________________________
There are two types of vessels, submarines and targets.

Top
#111553 - 2004-01-09 04:29 PM Re: Strange behavior of Task Scheduling tools...
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
Jens... if you have installed XP SP1, the version of schtasks.exe is slightly different and the link you provide no longer works.

Co, offer still stands if you need it.


Top
Page 1 of 1 1


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 557 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.055 seconds in which 0.022 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org