FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour GetTasks() Function
Posts: 842
Joined: Mon Oct 10, 2005 01:29 PM

GetTasks() Function

Posted: Fri Oct 16, 2015 02:55 PM

Antonio

I have to close a program (that is in Try Icon Bar )
I tryed with GetTasks() but the program is not in the list , but if I open task manger insted it is.

Thank in anticipation
Maurizio

www.nipesetvice.com

Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM

Re: GetTasks() Function

Posted: Fri Oct 16, 2015 04:15 PM
Maurizio,

You could try with the old FWH function GetTasks():

Code (fw): Select all Collapse
#include "FiveWin.ch"

#define GHW_HWNDFIRST 0
#define GHW_HWNDNEXT  2

#define GWW_HINSTANCE -6

//----------------------------------------------------------------------------//

function GetTasks()

   local hWnd   := GetWindow( GetActiveWindow(), GHW_HWNDFIRST )
   local aTasks := {}
   local cTask

   while hWnd != 0
      #ifdef __CLIPPER__
         cTask = GetModuleFileName( GetWindowWord( hWnd, GWW_HINSTANCE ) )
      #else
         // cTask = GetModuleFileName( GetWindowLong( hWnd, GWW_HINSTANCE ) )
         cTask = GetWindowText( hWnd ) // The above does now work :-(
      #endif

      if AScan( aTasks, cTask ) == 0
         AAdd( aTasks, cTask )
      endif
      hWnd = GetWindow( hWnd, GHW_HWNDNEXT )
   end

return aTasks

//----------------------------------------------------------------------------//

#define HKEY_CURRENT_USER 2147483649
#define REG_DWORD 4

function SetTaskManager( lOnOff ) // Enables/Disables Ctrl+Alt+Del

   local hKey := 0

   if lOnOff
      RegCreateKey( HKEY_CURRENT_USER,;
      "Software\Microsoft\Windows\CurrentVersion\Policies\System", @hKey )
      RegSetValue( hKey, "DisableTaskMgr", 0, REG_DWORD, L2BIN( 0 ), 4 )
      RegCloseKey( hKey )
   else
      RegCreateKey( HKEY_CURRENT_USER,;
      "Software\Microsoft\Windows\CurrentVersion\Policies\System", @hKey )
      RegSetValue( hKey, "DisableTaskMgr", 0, REG_DWORD, L2BIN( 1 ), 4 )
      RegCloseKey( hKey )
   endif

return nil

DLL32 static FUNCTION REGCREATEKEY( hKey AS LONG, cSubKey AS LPSTR, @nHandle AS ;
      PTR ) AS LONG PASCAL FROM "RegCreateKeyA" LIB "advapi32.dll"

DLL32 static FUNCTION REGSETVALUE( hKey AS LONG, cValueName AS LPSTR, nReserved AS ;
      LONG, nType AS DWORD, cData AS LPSTR, nData AS DWORD ) AS LONG ;
      PASCAL FROM "RegSetValueExA" LIB "advapi32.dll"

DLL32 static FUNCTION REGCLOSEKEY( hKey AS LONG ) AS LONG ;
      PASCAL FROM "RegCloseKey" LIB "advapi32.dll"
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 80
Joined: Tue Mar 25, 2008 09:03 PM

Re: GetTasks() Function

Posted: Fri Oct 16, 2015 06:39 PM

Non ricordo dove l'ho trovato ...

KillProcess("menu.exe")

FUNCTION KillProcess( cExe )

local oWmi, oList, oProc

oWmi := WmiService()
oList := oWmi:ExecQuery( "select * from Win32_Process where Name = '" + cExe + "'" )
for each oProc in oList
oProc:Terminate()
next
return nil

FUNCTION WMIService()
// It would be useful to keep this function in the library
static oWMI

local oLocator

if oWMI == nil

  oLocator   := CREATEOBJECT( "wbemScripting.SwbemLocator" )
  oWMI       := oLocator:ConnectServer()

endif

return oWMI

Stefano

FWH 14.11 + xHarbour + bcc582
Posts: 842
Joined: Mon Oct 10, 2005 01:29 PM

Re: GetTasks() Function

Posted: Mon Oct 19, 2015 09:43 AM

Thank Antonio and Stefano
they both work

Maurizio

www.nipeservice.com

Continue the discussion