如何从桌面应用程序知道某些进程是否在Windows ce设备上运行

本文关键字:Windows 是否 ce 运行 进程 桌面 应用程序 | 更新日期: 2023-09-27 18:33:19

我想知道某些进程是否正在Windows Ce设备上从桌面应用程序抛出RAPI

如何从桌面应用程序知道某些进程是否在Windows ce设备上运行

RAPi 本身没有任何进程管理/工具帮助功能,因此开箱即用,您无法执行此操作。 我的建议是创建一个自定义的 RAPI DLL(这里的例子 - 不幸的是,这必须在 C 中完成,但它非常简单),它要么只是通过工具帮助检查你的进程,要么是一个更通用的版本,允许你枚举正在运行的进程,然后使用 CeRapiInvoke 调用该 DLL。

共享源 OpenNETCF 桌面通信库具有此函数的包装器。

我找到了一个不同的解决方案,并且似乎它正在工作。 这个想法是让应用程序的窗口运行,并搜索应用程序的标题,我认为它不太灵活,但现在还可以,也许稍后我会为 CeRapiInvoke 解决方案更改它。终于开始工作了

    [DllImport("rapi.dll", SetLastError = true)]
    internal static extern IntPtr CeGetWindow(IntPtr hWnd, GetWindow_Cmd uCmd);
    [DllImport("rapi.dll", CharSet = CharSet.Unicode, SetLastError = true)]
    internal static extern int CeGetWindowText(IntPtr hWnd, StringBuilder name, int nMaxCount);
    public enum GetWindow_Cmd : uint
    {
        GW_HWNDFIRST = 0,
        GW_HWNDLAST = 1,
        GW_HWNDNEXT = 2,
        GW_HWNDPREV = 3,
        GW_OWNER = 4,
        GW_CHILD = 5,
        GW_ENABLEDPOPUP = 6
    }

    public bool TaskIsRunning(string windowName)
    {
        IntPtr ptr = CeGetWindow(IntPtr.Zero, GetWindow_Cmd.GW_CHILD);
        ptr = CeGetWindow(ptr, GetWindow_Cmd.GW_HWNDLAST);
        while (ptr != IntPtr.Zero)
        {
            StringBuilder sb = new StringBuilder(255);
            //string lala = new string(' ', 255);
            //lala = null;
            int a = CeGetWindowText(ptr, sb, 255);
            System.Diagnostics.Debug.WriteLine(a + " " + sb.ToString());
            if (sb.ToString() == windowName)
                return true;
            ptr = CeGetWindow(ptr, GetWindow_Cmd.GW_HWNDPREV);
        }
        return false;
    }

希望这对其他人有所帮助