我想知道是否某个进程正在从Windows桌面应用程序抛出RAPI的Windows CE设备上运行
RAPi本身并不具有任何流程管理/工具帮助功能,因此您无法做到这一点。 我的建议是创建一个自定义RAPI DLL( 这里的例子 – 不幸的是这必须在C中完成,但是非常简单),只需要通过toolhelp检查你的进程,或者使用一个更通用的方法来枚举正在运行的进程,然后使用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; }
希望这可以帮助别人