コード例 #1
0
        public static string GetUwpApplicationName(IntPtr hWnd, uint processId)
        {
            var windowInfo = new WindowInfo
            {
                OwnerPid = processId,
                ChildPid = processId
            };

            var pWindowInfo = Marshal.AllocHGlobal(Marshal.SizeOf(windowInfo));

            Marshal.StructureToPtr(windowInfo, pWindowInfo, false);
            LowLevel.EnumChildWindows(hWnd, EnumChildWindowsFunc, pWindowInfo);

            windowInfo = (WindowInfo)Marshal.PtrToStructure(pWindowInfo, typeof(WindowInfo));

            var proc = IntPtr.Zero;

            if (windowInfo != null)
            {
                proc = LowLevel.OpenProcess((uint)(ProcessAccess.QueryInformation | ProcessAccess.VirtualMemoryRead),
                                            false, (int)windowInfo.ChildPid);

                if (proc == IntPtr.Zero)
                {
                    return(null);
                }
            }

            var capacity = 2048;
            var buffer   = new StringBuilder(capacity);

            LowLevel.QueryFullProcessImageName(proc, 0, buffer, ref capacity);

            Marshal.FreeHGlobal(pWindowInfo);

            return(buffer.ToString(0, capacity));
        }