Search code examples
javagoogle-chromewinapijna

Get all chrome windows


I want to get all chrome windows running currently. The below code will get all the windows.

final WinDef.HWND[] windowHandle = new WinDef.HWND[1];

    User32.INSTANCE.EnumWindows(new WinUser.WNDENUMPROC() {
        @Override
        public boolean callback(WinDef.HWND hwnd, Pointer pointer) {
            if (matches(hwnd)) {
                windowHandle[0] = hwnd;
                return false;
            }
            return true;
        }
    }, Pointer.NULL);

How can I only get running chrome windows ?


Solution

  • I think will be better to use already completed third party library like a Sigar. https://support.hyperic.com/display/SIGAR/Home

    You will get API for work with processes. At least you can look at source code.

    Sigar sigar = new Sigar();
    ProcessFinder find = new ProcessFinder(sigar);
    find.find("Exe.Name.ct=chrome");