Ejemplo n.º 1
0
        /// <summary>
        /// Lists current running process.
        /// </summary>
        /// <returns></returns>
        public static Process[] GetProcesses()
        {
            List <Process> list   = new List <Process>();
            IntPtr         handle = NativeMethods.CreateToolhelp32Snapshot(NativeMethods.TH32CS.SNAPPROCESS, 0);

            if (((int)handle) <= 0)
            {
                int error = Tenor.Mobile.NativeMethods.GetLastError();
                throw new Exception(string.Format("Unable to create snapshot. Error {0}.", error));
            }
            try
            {
                byte[] pe    = new NativeMethods.PROCESSENTRY32().ToByteArray();
                byte[] array = new byte[pe.Length];
                pe.CopyTo(array, 0);
                for (int i = NativeMethods.Process32First(handle, pe); i == 1; i = NativeMethods.Process32Next(handle, pe))
                {
                    NativeMethods.PROCESSENTRY32 processentry = new NativeMethods.PROCESSENTRY32(pe);
                    Process proc = new Process(processentry);
                    list.Add(proc);
                }
            }
            finally
            {
                NativeMethods.CloseToolhelp32Snapshot(handle);
            }

            foreach (Process p in list)
            {
                try
                {
                    p.pEntry.szExeFile = GetProcessPath((uint)p.pEntry.ProcessID);
                }
                catch { }
            }

            return(list.ToArray());
        }
Ejemplo n.º 2
0
 private Process(NativeMethods.PROCESSENTRY32 pEntry)
 {
     this.pEntry = pEntry;
 }