Sabtu, Mei 10, 2008

Check Applikasi Running di Windows

{ Vfp Code }
DIMENSION awin_apps[1]
* --- Initialize variable to store handle for current application
vfp_handle=0
* --- Declare API Functions
DECLARE INTEGER FindWindow ;
IN win32api ;
INTEGER nullpointer, ;
STRING cwindow_name
DECLARE INTEGER GetWindow ;
IN win32api ;
INTEGER ncurr_window_handle, ;
INTEGER ndirection
DECLARE INTEGER GetWindowText ;
IN win32api ;
INTEGER n_win_handle, ;
STRING @ cwindow_title, ;
INTEGER ntitle_length
* --- End of API function declarations
* --- Get handle for current application
app_screen = FindWindow(0,_SCREEN.CAPTION)
* --- Store handle of current app to a variable
ln_current_window = app_screen
* --- Initialize a count variable used to dimension array of running apps
ln_window_count = 0
DO WHILE ln_current_window > 0
* --- Initialize variable to store application title
lc_window_title=SPACE(255)
* --- Call to GetWindowText to fetch window caption
ln_length=GetWindowText(ln_current_window, ;
@lc_window_title,LEN(lc_window_title))
* --- Note that the lc_window_title variable is used as a buffer to
* --- receive text from the call to GetWindowText
IF ln_length>0
lc_window_title=STRTRAN(TRIM(lc_window_title),CHR(0),"")
ELSE
lc_window_title=""
ENDIF
IF ln_current_window>0 .AND. !EMPTY(lc_window_title)
* --- Increment the window count and re-dimension the array of running
* --- applications
ln_window_count=ln_window_count+1
DIMENSION awin_apps(ln_window_count)
awin_apps[ln_Window_Count]=lc_window_title
ENDIF
* --- Call to GetWindow to fetch handle of running applications.
ln_current_window=GetWindow(ln_current_window,2)
ENDDO
* --- Get a unique file name for this in the event this is run
* --- on a centralized multi-user server
isrunfyl=SUBSTR(SYS(2015),3,10)
* --- Create a free table based upon unique name
CREATE CURSOR isrunfyl (appname C(200))
*USE &isrunfyl ALIAS isrunfyl
* --- Fill the table
IF ALEN(awin_apps,1) > 0
SELECT isrunfyl
FOR i=1 TO ALEN(awin_apps,1)
APPEND BLANK
REPLACE appname WITH ALLTRIM(awin_apps[i])
NEXT
ENDIF
GOTO TOP
SELECT appname,COUNT(appname) AS counted ;
FROM isrunfyl ;
INTO CURSOR ctemp ;
ORDER BY appname GROUP BY appname
USE IN isrunfyl
SELECT appname,counted ;
FROM ctemp INTO CURSOR ctemp ORDER BY counted DESC
SELECT ctemp
BROWSE NORMAL

{ End Code }

Tidak ada komentar: