Display a Task List

This forum is for eXpress++ general support.
Post Reply
Message
Author
User avatar
rdonnay
Site Admin
Posts: 4734
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Display a Task List

#1 Post by rdonnay »

Here is a program that displays all running tasks.
Right click on a task to kill that task.

Code: Select all

#INCLUDE "dcdialog.CH"

FUNCTION Main()

LOCAL GetList[0], aTasks, i, oBrowse, aHeader, GetOptions, oMenu, aWidths

RunShell('/C TaskList.Exe /V /FO CSV > tasklist.csv')

aTasks := DC_Csv2Array('tasklist.csv')

IF Empty(aTasks)
  DCMSGBOX 'Could not create TASKLIST.CSV'
ENDIF

aHeader := aTasks[1]
aWidths := Array(Len(aTasks[1]))
AFill(aWidths,10)
aWidths[1] := 25
aWidths[2] := 5
aWidths[3] := 5
aWidths[4] := 6
aWidths[9] := 40

ARemove( aTasks,1 )
ASort(aTasks,,,{|a,b|a[1]<b[1]})

@ 0,0 DCPUSHBUTTON CAPTION 'Refresh Task List' SIZE 15 ;
      ACTION {||RefreshTasks(oBrowse,@aTasks)}

@ 1,0 DCBROWSE oBrowse SIZE 30,25 FIT ;
      DATA aTasks ;
      RBSELECT ;
      RESIZE DCGUI_RESIZE_RESIZEONLY ;
      FONT '9.Lucida Console'

FOR i := 1 TO Len(aHeader)
  DCBROWSECOL ELEMENT i HEADER aHeader[i] PARENT oBrowse ;
      EVAL {|o|o:dataArea:rbdown := {|x,y,z|oMenu:popup( z, x, 2 , ;
                     XBPMENU_PU_DEFAULT + XBPMENU_PU_MOUSE_RBDOWN ) }} ;
  SORT SortBlock(aTasks,i) ;
  WIDTH aWidths[i]
NEXT

DCSUBMENU oMenu PROMPT 'Options'
  DCMENUITEM 'Kill Task' PARENT oMenu ;
     ACTION {||KillTask(oBrowse,@aTasks,aHeader) }

DCGETOPTIONS RESIZE

DCREAD GUI FIT TITLE 'Browsing Task List' SETAPPWINDOW OPTIONS GetOptions

RETURN nil


PROC appsys ; RETURN

* ---------

STATIC FUNCTION SortBlock( aTasks, i )

RETURN {||ASort(aTasks,,,{|a,b|a[i]<b[i]})}

* ---------

STATIC FUNCTION KillTask( oBrowse, aTasks, aHeader )

LOCAL aTask := aTasks[oBrowse:arrayElement], i, aMsg, lStatus

aMsg := { 'Kill Task:', '' }

FOR i := 1 TO Len(aHeader)
  AAdd(aMsg,PadL(aHeader[i],15) + ': ' + aTask[i])
NEXT

lStatus := DC_MsgBox(,,aMsg,,,,.t.,2,,,,,'12.Lucida Console')

IF lStatus
  RunShell('/PID ' + aTask[2],'C:\windows\system32\TaskKill.Exe',.t.,.f.)
  Sleep(100)
  RefreshTasks( oBrowse, @aTasks )
ENDIF

RETURN lStatus

* ----------

STATIC FUNCTION RefreshTasks( oBrowse, aTasks )

RunShell('/C TaskList.Exe /V /FO CSV > tasklist.csv')
aTasks := DC_Csv2Array('tasklist.csv')
ARemove( aTasks,1 )
ASort(aTasks,,,{|a,b|a[1]<b[1]})
oBrowse:dataSource := aTasks
oBrowse:goTop()
oBrowse:forceStable()
oBrowse:refreshAll()

RETURN nil
The eXpress train is coming - and it has more cars.

User avatar
rdonnay
Site Admin
Posts: 4734
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: Display a Task List

#2 Post by rdonnay »

You will also need this new function:

Code: Select all

FUNCTION DC_CSV2Array( cCsvFileName )

LOCAL nHandle, cLine, aTokens, aCSV[0]

nHandle := DC_TxtOpen( cCsvFileName )

IF  nHandle <= 0
  RETURN {}
ENDIF

DO WHILE !DC_TxtEof(nHandle)
  cLine := DC_TxtLine(nHandle,Chr(10))
  aTokens := DC_TokenArray(cLine,',',.t.)
  AAdd( aCSV, aTokens )
  DC_TxtSkip(nHandle,1,Chr(10))
ENDDO

DC_TxtClose( nHandle )

RETURN aCSV
The eXpress train is coming - and it has more cars.

Victorio
Posts: 631
Joined: Sun Jan 18, 2015 11:43 am
Location: Slovakia

Re: Display a Task List

#3 Post by Victorio »

Hi,

I tryed this utility, but error occured
Error Base/1012
Description :Error in array index
Operation : <A of 0 >[<1>]
Thread ID 1

at row aWidths[1]:=25

I tryed on Windows XP OS.

User avatar
rdonnay
Site Admin
Posts: 4734
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: Display a Task List

#4 Post by rdonnay »

I tryed on Windows XP OS.
It could be that TaskList.Exe doesn't work on XP.

I have used this on Windows 7 and 2012 Server.
The eXpress train is coming - and it has more cars.

User avatar
Tom
Posts: 1177
Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany

Re: Display a Task List

#5 Post by Tom »

I tryed on Windows XP OS.
Don't use XP anymore. Microsoft stopped supporting this OS in january, and it's highly risky using it.
Best regards,
Tom

"Did I offend you?"
"No."
"Okay, give me a second chance."

Victorio
Posts: 631
Joined: Sun Jan 18, 2015 11:43 am
Location: Slovakia

Re: Display a Task List

#6 Post by Victorio »

OK, thank´s for info. I will try on W7, ...

I know, XP have not support, but in our office we have 50 PC with XP , and 3 servers with Windows 2003 server, that also have not support.
Problem is with old special application not correct run on WIndows 7 or newer os.

At home I still have PC with Windows 98 :), on this I have programmer for PIC processors and other hardware interfaces, second with W XP, third with Windows 7 32, notebook with Windows 8.1 64bit, and want install virtual Windows 10 :)

Victorio
Posts: 631
Joined: Sun Jan 18, 2015 11:43 am
Location: Slovakia

Re: Display a Task List

#7 Post by Victorio »

Hi,
I found problem, on Windows XP tasklist.csv generating with first blank row. If I erase it, utility browse tasks.

Victorio
Posts: 631
Joined: Sun Jan 18, 2015 11:43 am
Location: Slovakia

Re: Display a Task List

#8 Post by Victorio »

Here is "my" modify for Win XP,
If "some" funcion test version OS, for example :

OS=testOS() - this function I have not now...

it may be universal for Windows XP and WIndows 7,

FUNCTION DC_CSV2Array( cCsvFileName )

LOCAL nHandle, cLine, aTokens, aCSV[0]

nHandle := DC_TxtOpen( cCsvFileName )

IF nHandle <= 0
RETURN {}
ENDIF

row=1
DO WHILE !DC_TxtEof(nHandle)

if row=1 .and. OS="WindowsXP"
DC_TxtSkip(nHandle,1,Chr(10))
else
cLine := DC_TxtLine(nHandle,Chr(10))
aTokens := DC_TokenArray(cLine,',',.t.)
AAdd( aCSV, aTokens )
DC_TxtSkip(nHandle,1,Chr(10))
endif
row++
ENDDO

DC_TxtClose( nHandle )

RETURN aCSV

Post Reply