private ProcessEntry(PROCESSENTRY32 pe)
		{
			m_pe = pe;
		}
		/// <summary>
		/// Rerieves an array of all running processes
		/// </summary>
		/// <returns></returns>
		public static ProcessEntry[] GetProcesses()
		{
			ArrayList procList = new ArrayList();

			IntPtr handle = Util.CreateToolhelp32Snapshot(Util.TH32CS_SNAPPROCESS, 0);

			if ((int)handle > 0)
			{
				try
				{
					PROCESSENTRY32 peCurrent;
					PROCESSENTRY32 pe32 = new PROCESSENTRY32();
					//Get byte array to pass to the API calls
					byte[] peBytes = pe32.ToByteArray();
					//Get the first process
					int retval = Util.Process32First(handle, peBytes);

					while(retval == 1)
					{
						//Convert bytes to the class
						peCurrent = new PROCESSENTRY32(peBytes);
						//New instance
						ProcessEntry proc = new ProcessEntry(peCurrent);
			
						procList.Add(proc);

						retval = Util.Process32Next(handle, peBytes);
					}
				}
				catch(Exception ex)
				{
					throw new Exception("Exception: " + ex.Message);
				}
				
				//Close handle
				Util.CloseToolhelp32Snapshot(handle); 
				
				return (ProcessEntry[])procList.ToArray(typeof(ProcessEntry));

			}
			else
			{
				throw new Exception("Unable to create snapshot");
			}


		}
示例#3
0
 private ProcessEntry(PROCESSENTRY32 pe)
 {
     m_pe = pe;
 }