예제 #1
0
        /// <summary>Query the time the process was created.</summary>
        /// <param name="pid">The process id.</param>
        /// <returns>The time the process was created or <see cref="DateTime.MinValue"/> if an error occurs.</returns>
        private DateTime GetProcessCreateTime(int pid)
        {
            IntPtr handle = IntPtr.Zero;

            try
            {
                handle = nativeHelper.OpenRemoteProcess((int)pid, NativeMethods.PROCESS_QUERY_LIMITED_INFORMATION);
                if (!handle.IsNull())
                {
                    long dummy;
                    long create;
                    if (NativeMethods.GetProcessTimes(handle, out create, out dummy, out dummy, out dummy))
                    {
                        return(DateTime.FromFileTime(create));
                    }
                }
            }
            catch
            {
            }
            finally
            {
                if (!handle.IsNull())
                {
                    nativeHelper.CloseRemoteProcess(handle);
                }
            }

            return(DateTime.MinValue);
        }