Пример #1
0
        public static PsInfo GetExecutablePath()
        {
            try
            {
                var c     = GetMousePosition();
                var point = Win32Point.NewPoint(c.X, c.Y);
                var hWnd  = WindowFromPoint(point);

                var threadId = GetWindowThreadProcessId(hWnd, out uint processId);

                var ps       = Process.GetProcessById((int)processId);
                var fileName = ps.MainModule.FileName;

                return(new PsInfo()
                {
                    HWnd = $"ThreadId: {threadId} - ProcessId: {processId} - hWnd: {hWnd}",
                    FileName = fileName.ToString()
                });
            }
            catch (Win32Exception ex)
            {
                if (ex.ErrorCode.ToString("X") == "80004005")
                {
                    throw new NotSupportedException($"You don't have sufficient right to access the process. You probably must have administration rights for this application, which is not yet supported.", ex);
                }
                else
                {
                    throw GenericException(ex);
                }
            }
            catch (Exception ex) { throw GenericException(ex); }
        }
Пример #2
0
        private static Win32Point GetMousePosition()
        {
            GetCursorPos(out var p);

            return(Win32Point.NewPoint(p.X, p.Y));
        }