GetTasks() Function

GetTasks() Function

Postby Maurizio » Fri Oct 16, 2015 2: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
User avatar
Maurizio
 
Posts: 796
Joined: Mon Oct 10, 2005 1:29 pm

Re: GetTasks() Function

Postby Antonio Linares » Fri Oct 16, 2015 4:15 pm

Maurizio,

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

Code: Select all  Expand view
#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
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: GetTasks() Function

Postby stefano » Fri Oct 16, 2015 6: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
stefano
 
Posts: 80
Joined: Tue Mar 25, 2008 9:03 pm
Location: ITALIA

Re: GetTasks() Function

Postby Maurizio » Mon Oct 19, 2015 9:43 am

Thank Antonio and Stefano
they both work

Maurizio
www.nipeservice.com
User avatar
Maurizio
 
Posts: 796
Joined: Mon Oct 10, 2005 1:29 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 94 guests