Foxpro访问运行进程的Windows以及如何结束正在运行的进程

时间:2011-04-28 16:36:49

标签: visual-foxpro foxpro

如何在Foxpro 9中获取任务管理器运行进程的列表,以及如何在FoxPro的列表中终止其中一个进程?

2 个答案:

答案 0 :(得分:0)

这是一个杀死特定程序的所有可见实例的函数。您需要知道它的ClassName。我已经能够通过搜索找到常见应用程序(如Office应用程序)的ClassNames:

FUNCTION KillApp
*==============================================================================
* Program:              KillApp.PRG
* Purpose:              Close any invisible instances of a specified program
* Author:               Tamar E. Granor
* Last revision:            04/16/02
* Parameters:           tcClassName - the classname of the app to close
* Returns:              Number of instances closed; -1, if parameter problems
* Environment in:       
* Environment out:      Several API functions declared
*==============================================================================
#DEFINE GW_CHILD 5
#DEFINE GW_HWNDNEXT 2
#DEFINE WM_CLOSE 0x10 

LPARAMETERS tcClassName

ASSERT VARTYPE(tcClassName) = "C" AND NOT EMPTY(tcClassName) ;
    MESSAGE "KillApp: Must pass class name of application to kill"

IF VARTYPE(tcClassName) <> "C" OR EMPTY(tcClassName)
    ERROR 11
    RETURN -1
ENDIF

DECLARE LONG GetDesktopWindow IN WIN32API 
DECLARE LONG GetWindow IN WIN32API LONG hWnd, LONG wCmd
DECLARE LONG IsWindowVisible IN WIN32API LONG hWnd
DECLARE LONG GetClassName IN WIN32API LONG hWnd, STRING lpClassName, LONG nMaxCount 
DECLARE LONG PostMessage IN WIN32API LONG hwnd, LONG wMsg, LONG wParam, LONG lParam 

LOCAL lnDesktopHWnd, lnHWnd, lnOldHWnd, lcClass, lnLen, nClosedCount

lnDesktopHWnd = GetDesktopWindow()
lnHWnd = GetWindow( lnDesktopHWnd, GW_CHILD)
lnClosedCount = 0

DO WHILE lnHWnd <> 0
    lcClass = SPACE(256)
    lnLen = GetClassName( lnHWnd, @lcClass, 256)
    lnOldHWnd = lnHWnd
    lnHWnd = GetWindow(lnOldHWnd, GW_HWNDNEXT)
    IF UPPER(LEFT(lcClass, lnLen)) = UPPER(tcClassName)
        lnVisible = IsWindowVisible(lnOldHWnd)
        IF lnVisible = 0
            PostMessage( lnOldHWnd, WM_CLOSE, 0, 0)
            lnClosedCount = lnClosedCount + 1 
        ENDIF 
    ENDIF 
ENDDO

RETURN lnClosedCount

刚刚意识到某个进程可能与应用程序不同。看起来用于查找进程的API函数是EnumProcesses。查看http://www.news2news.com/vfp/?group=-1&function=246

答案 1 :(得分:0)

使用WMI可以轻松完成。有一个使用WIN32_Process http://www.berezniker.com/content/pages/visual-foxpro/check-if-exe-running-and-optionally-terminate-it终止流程的示例实现,也可以轻松调整以列出流程。