Page 1 of 1 1
Topic Options
#149579 - 2005-10-10 08:39 AM Active Task List
knsk80 Offline
Fresh Scripter

Registered: 2002-07-17
Posts: 45
Loc: KL
Hi Gurus,
Anyone out there has any idea on how to get Active Task List? I need to enumerate all my active task under Task Manager - Applications.

I've tried to search, but so far i've only gotten results for Processes List which can be obtain in WMI Win32_Process.

Really appreaciate if any of you can shed some light on this matter.

thanks
Kenneth

Top
#149580 - 2005-10-10 10:25 AM Re: Active Task List
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4572
Loc: USA
It seems like there has got to be a better way but...

http://www.microsoft.com/technet/scriptcenter/topics/office/tasks.mspx

Code:
 break on
$objWord = CreateObject("Word.Application")
$colTasks = $objWord.Tasks

For Each $objTask in $colTasks
If $objTask.Visible
? $objTask.Name
EndIf
Next

$objWord.Quit

_________________________
(... better days ahead)

Top
#149581 - 2005-10-10 11:43 AM Re: Active Task List
knsk80 Offline
Fresh Scripter

Registered: 2002-07-17
Posts: 45
Loc: KL
Yeah, i found that out.. but If i'm not mistaken it needs microsoft word installed rite? I'm trying to find out whether can WMI or Kix can handle this or not.
Top
#149582 - 2005-10-10 12:10 PM Re: Active Task List
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Quote:

but If i'm not mistaken it needs microsoft word installed rite?




Right.

You can also use AutoIT to enumerate open windows, which is pretty much what the task list is. Unfortunately the window enumeration function is not exposed in the AutoIT DLL so you need to run an AutoIT script and parse it.

If your target systems are XP you can use the command line "tasklist" to get you pretty close. Use "tasklist /FO:TABLE /V" to get a verbose list of processes in a fixed-width format. Parse the output and discard anything with a "Window Title" of "N/A".

You will get some extra tasks where the windows have been created but are hidden, but it might be close enough for your needs.

Top
#149583 - 2005-10-12 03:42 PM Re: Active Task List
knsk80 Offline
Fresh Scripter

Registered: 2002-07-17
Posts: 45
Loc: KL
Hi, I thot that i might share, my findings so that others who need the same thing will end there search here.

I've been using AutoIT to parse the results but unfortunately it has some side effect or something, it cause my screen to blink a few times.

I manage to use cmdow.exe as an alternative. i got it from http://www.commandline.co.uk/cmdow
It didn't work quite well with Kix, because when i shell it, it will give me error. So i created a batch file instead and used kix to read out the generated file.

Hope this help for others.

Thanks Allen and Richard for your help.

Top
#149584 - 2005-10-12 04:10 PM Re: Active Task List
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
This works for me:
Code:
$=SetOption("WrapAtEOL","ON")
For Each $sLine in WshPipe("cmdow.exe /b /t /f")
If $sLine
$sLine=Split($sLine)
$sHandle=$sLine[0]
$sLev=$sLine[1]
$sPID=$sLine[2]
$sStatus=$sLine[3]+","+$sLine[4]+","+$sLine[5]+","+$sLine[6]
$sImage=$sLine[7]
$sCaption=SubStr(Join($sLine),Len(Join($sLine," ",8))+2)
"'"+$sCaption+"'" ?
EndIf
Next

; WshPipe() ripped from Chris Shilt's UDF post: http://www.kixtart.org/ubbthreads/showflat.php?Cat=0&Number=82578&an=&page=0&vc=1
Function WshPipe($ShellCMD)
Dim $oExec, $Output
$oExec = CreateObject("WScript.Shell").Exec($ShellCMD)
If Not VarType($oExec)=9 $WshPipe="WScript.Shell Exec Unsupported" Exit 10 EndIf
$Output = $oExec.StdOut.ReadAll + $oExec.StdErr.ReadAll
$WshPipe=Split(Join(Split($Output,CHR(13)),''),CHR(10))
Exit($oExec.ExitCode)
EndFunction


Top
#149585 - 2005-10-13 04:53 AM Re: Active Task List
knsk80 Offline
Fresh Scripter

Registered: 2002-07-17
Posts: 45
Loc: KL
Wow,
thanks Richard.

Top
#149586 - 2005-10-13 07:28 AM Re: Active Task List
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Thanks for the code Richard.

Don't forget to set the other options though

 
Code:
Break On
Dim $SO
$SO=SetOption('Explicit','On')
$SO=SetOption('NoVarsInStrings','On')
$SO=SetOption('NoMacrosInStrings','On')
$SO=SetOption("WrapAtEOL","ON")
 
Dim $sLine,$sHandle,$sLev,$sPID,$sStatus,$sImage,$sCaption


Top
#149587 - 2005-10-13 10:03 AM Re: Active Task List
knsk80 Offline
Fresh Scripter

Registered: 2002-07-17
Posts: 45
Loc: KL
Sorry NTDoc,
What are these options listed there for?
I've never set any of them before.

Top
#149588 - 2005-10-13 10:20 AM Re: Active Task List
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Quote:


Break On




Lets you close the script without being logged of.

Quote:


Dim $SO
and
Dim $sLine,$sHandle,$sLev,$sPID,$sStatus,$sImage,$sCaption




Declares variables.

Quote:


$SO=SetOption('Explicit','On')




States the all var’s should be DIM'ed

Quote:


$SO=SetOption('NoVarsInStrings','On')




Does not allow variables to be used inside strings.

Quote:


$SO=SetOption('NoMacrosInStrings','On')




Does not allow macro’s to be used inside strings.

Quote:


$SO=SetOption("WrapAtEOL","ON")




Enables wrapping of console output at the end of a line.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
Page 1 of 1 1


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

Who's Online
0 registered and 1644 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.077 seconds in which 0.048 seconds were spent on a total of 12 queries. Zlib compression enabled.

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