#172296 - 2007-01-02 03:31 AM
Re: tcdefinetrigger() help
[Re: itdaddy]
|
Glenn Barnas
KiX Supporter
Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
|
Actually, I think what you really want is the SUSpend option, which disables the event, not just one trigger.
Here's an example to disable any task called "BadTask". You could just as easily check the executable, user ID, or whatever.. We changed the password on the task scheduling account and had to locate every task that used that account on every server (300+) and change the credentials. Took a few minutes to complete.
You need to wrap this into your own code to read the computer names from a file or AD or somewhere...
; This is in a loop, which enumerates all your
; remote computers in the variable $Target
tcInit(1)
; just suspend a specific task event
$Task = "BadTask"
tcGetEvent($Target, $Task) ; load the bad task data
tcDefineTask("SUS=1") ; set it to Suspend (disable)
tcSetEvent($Target, $Task) ; update the task on the target
; alternative code, looks at each task for a command name (or other setting)
; if the command contains "xyzzy.exe", the task is suspended
$TaskList = tcGetTasks($Target)
For Each $Task in $TaskList
tcGetEvent($Target, $Task) ; load the task data
If InStr($a_tcTask[0], "xyzzy.exe")
tcDefineTask("SUS=1") ; set it to Suspend (disable)
tcSetEvent($Target, $Task) ; update the task on the target
EndIf
Next
Read the first section of the manual - it defines the difference between tasks and triggers. An "event" consists of one "task" (what to do) and up to 10 "triggers" (when to do it). It's more likely that you want to disable the task (which disables all triggers!) and not just a trigger.
Unfortunately, the "Suspend" mnemonic isn't as clear as "Disable" could be, but it's Microsoft's code in JT.exe.
Also, be sure to use tcInit(1), which sets the array to nulls, before each read you do. Be sure to READ the event into the array, then use tcDefineT**** to UPDATE the array, so you can write it back. the tcDefineT*** UDFs only manipulate the array - you must first tcGetEvent() to load the array before updating it and writing it back with tcSetEvent().
You probably should also use a tcDefineTask("PWD=xxxxx") to properly set the password before you write the task back. I believe the password is required to perform any updates.
Glenn
_________________________
Actually I am a Rocket Scientist!
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 507 anonymous users online.
|
|
|