Question

I want to know if certain process is running on a Windows Ce device from a desktop application throw RAPI

Was it helpful?

Solution

RAPi doesn't inherently have any process management/toolhelp functionality so out of the box you can't do this. What my recommendation would be is create a custom RAPI DLL (example here - unfortunately this has to be done in C, but it's pretty straightforward) that either just checks your process via toolhelp, or a more generic version that allows you to enumerate running processes, then use CeRapiInvoke to call that DLL.

The shared source OpenNETCF Desktop Communication library has a wrapper for this function.

OTHER TIPS

I found a different solution, and seems it's working. the idea its get the windows of the apps running, and search for the title of the app, its less flexible i think but its ok for now, maybe later im going to change it for the CeRapiInvoke solution. finally get this working

    [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;
    }

hope this help someone else

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top