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

发布于 2024-11-03 18:25:51 字数 60 浏览 0 评论 0原文

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

How do I get a list of the Task manager running processes in Foxpro 9, and how can I kill one of these processes in the list in FoxPro?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

魔法少女 2024-11-10 18:25:51

使用 WMI 可以让这变得简单。在 http://www.berezniker.com/content/pages/visual-foxpro/check-if-exe-running-and-optionally-terminate-it 也可以轻松适应列出进程。

Using WMI makes this easy. There's a sample implementation of terminating a process using WIN32_Process at http://www.berezniker.com/content/pages/visual-foxpro/check-if-exe-running-and-optionally-terminate-it which could also easily be adapted to list the processes.

无声无音无过去 2024-11-10 18:25:51

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

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&函数=246

添马舰

Here's a function to kill all visible instances of a particular program. You need to know its ClassName. I've been able to find ClassNames for common applications (like the Office apps) by searching:

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

Just realized that a process may not be the same as an application. It looks like the API function for finding processes is EnumProcesses. Check out http://www.news2news.com/vfp/?group=-1&function=246.

Tamar

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文