Process Info using c# provides access to local and remote processes and enables you to start and stop local system processes.
A Process component provides access to a process that is running on a computer. A process, in the simplest terms, is a running app. A thread is the basic unit to which the operating system allocates processor time. A thread can execute any part of the code of the process, including parts currently being executed by another thread. The Process component is a useful tool for starting, stopping, controlling, and monitoring apps. You can use the Process component, to obtain a list of the processes that are running, or you can start a new process. A Process component is used to access system processes. After a Process component has been initialized, it can be used to obtain information about the running process. Such information includes the set of threads, the loaded modules (.dll and .exe files), and performance information such as the amount of memory the process is using.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Diagnostics; | |
namespace killercodes_in.ProcssInformation | |
{ | |
struct ProcInfo | |
{ | |
internal string PName, PWinTitle, PMscNm, PMnMod, PMmFnm; | |
internal int PId, PBsPri, PExCod, PHwCnt, PMModMemSz, PSsnId, PThdCnt; | |
internal DateTime PExTim, PStrTime; | |
internal IntPtr PHwnd, PMmBsAdd, PMmEnPoAd, PMnWinHw, PMxWrkSt, PMinWrkSet, PProAff; | |
internal bool PHsExt, PResp, PPriBooEnb; | |
internal FileVersionInfo PMmFlVer; | |
internal TimeSpan PToProTm, PUsrProTim, PPrvProTim; | |
internal long PNonPgSysMemSiz, PWrkSet, PVirMemSiz, PPgMemSiz, PPgSysMemSiz, PPekPgMemSiz, PPekVirMemSiz, PPekWrkSet, PPvtMemSiz; | |
}; | |
class I_ProcInfo | |
{ | |
private const string usage = @"This is process Framework form killercodes.in, It shows various process info"; | |
private ProcInfo pn; | |
/// <summary> | |
/// Prints the usage information | |
/// </summary> | |
public string AboutIt | |
{ | |
get { return usage; } | |
} | |
#region Process Property | |
public int ProcessId { get { return pn.PId; } } | |
public string MainWindowTitle { get { return pn.PWinTitle; } } | |
public string ProcessName { get { return pn.PName; } } | |
public int BasePriority { get { return pn.PBsPri; } } | |
public int ExitCode { get { return pn.PExCod; } } | |
public IntPtr Handle { get { return pn.PHwnd; } } | |
public int HandleCount { get { return pn.PHwCnt; } } | |
public bool HasExited { get { return pn.PHsExt; } } | |
public string MachineName { get { return pn.PMscNm; } } | |
public string Mod_Filename { get { return pn.PMmFnm; } } | |
public FileVersionInfo Mod_Verinfo { get { return pn.PMmFlVer; } } | |
public int Mod_MemorySize { get { return pn.PMModMemSz; } } | |
public IntPtr Mod_BaseAddress { get { return pn.PMmBsAdd; } } | |
public IntPtr Mod_EntryPointAddress { get { return pn.PMmEnPoAd; } } | |
public string Mod_ModuleName { get { return pn.PMnMod; } } | |
public IntPtr MainWindowHandle { get { return pn.PMnWinHw; } } | |
public IntPtr MaxWorkingSet { get { return pn.PMxWrkSt; } } | |
public IntPtr MinWorkingSet { get { return pn.PMinWrkSet; } } | |
public bool Responding { get { return pn.PResp; } } | |
public int SessionId { get { return pn.PSsnId; } } | |
public int ThreadsCount { get { return pn.PThdCnt; } } | |
public TimeSpan TotalProcessTIme { get { return pn.PToProTm; } } | |
public TimeSpan UserProcessTIme { get { return pn.PUsrProTim; } } | |
public long NonPagedSysMemory { get { return pn.PNonPgSysMemSiz; } } | |
public long PageMemorySize { get { return pn.PPgMemSiz; } } | |
public long PagedSystemMemorySize { get { return pn.PPgSysMemSiz; } } | |
public long PeakPagedMemorySize { get { return pn.PPekPgMemSiz; } } | |
public long PeakVirtualMemorySize { get { return pn.PPekVirMemSiz; } } | |
public long PeakWorkingSet { get { return pn.PPekWrkSet; } } | |
public bool PriorityBoostEnabled { get { return pn.PPriBooEnb; } } | |
public long PrivateMemorySize { get { return pn.PPvtMemSiz; } } | |
public TimeSpan PrivilegedProcessTime { get { return pn.PPrvProTim; } } | |
public IntPtr ProcessorAffinity { get { return pn.PProAff; } } | |
public DateTime StartTime { get { return pn.PStrTime; } } | |
public long VirtualMemorySize { get { return pn.PVirMemSiz; } } | |
public long WorkingSet { get { return pn.PWrkSet; } } | |
#endregion | |
/// <summary> | |
/// Kills the process by the process name | |
/// </summary> | |
/// <param name="ProcName" /> | |
public void I_Kill(string ProcName) | |
{ | |
try | |
{ | |
Process[] processByName = Process.GetProcessesByName(ProcName); | |
//Process pogo = Process.GetProcesses(); | |
foreach (Process pr in processByName) | |
{ | |
pr.Kill(); | |
} | |
} | |
catch | |
{ | |
Console.WriteLine("Cannot terminate " + ProcName + "\n"); | |
} | |
} | |
/// <summary> | |
/// Kills process by process id | |
/// </summary> | |
/// <param name="Id" /> | |
public void I_Kill(int Id) | |
{ | |
try | |
{ | |
Process processById = Process.GetProcessById(Id); | |
processById.Kill(); | |
} | |
catch | |
{ | |
Console.WriteLine("Cannot terminate " + Id + "\n"); | |
} | |
} | |
/// <summary> | |
/// Gets all the running process | |
/// </summary> | |
public static void I_GetRunningProc() | |
{ | |
Process[] go = Process.GetProcesses(); | |
foreach (Process g in go) | |
{ | |
Console.WriteLine("{0}|{1}|{2}", g.ProcessName, g.MainWindowTitle, g.Id.ToString()); | |
} | |
} | |
/// <summary> | |
/// Gets the process name from the Id | |
/// </summary> | |
/// <param name="Id" /> | |
/// <returns></returns> | |
public string I_GetProcName(int Id) | |
{ | |
string res = "Process Not Found"; | |
Process[] pro = Process.GetProcesses(); | |
foreach (Process p in pro) | |
{ | |
if (p.Id.Equals(Id)) | |
{ | |
res = p.ProcessName; | |
break; | |
} | |
else | |
{ | |
res = "Process Not Found"; | |
} | |
} | |
return res; | |
} | |
/// <summary> | |
/// Gets the process Id from the process name | |
/// </summary> | |
/// <param name="pnm" /> | |
/// <returns></returns> | |
public int I_GetProcId(string pnm) | |
{ | |
int res = 0; | |
Process[] pro = Process.GetProcesses(); | |
foreach (Process p in pro) | |
{ | |
if (p.ProcessName.Equals(pnm)) | |
{ | |
res = p.Id; | |
break; | |
} | |
else | |
{ | |
res = 0; | |
} | |
} | |
return res; | |
} | |
/// <summary> | |
/// Gets all the information about the process specified with the name | |
/// </summary> | |
/// <param name="ProcessName" /> | |
public void I_GetProcInfo(string ProcessName) | |
{ | |
Process[] go = Process.GetProcesses(); | |
foreach (Process g in go) | |
{ | |
if (g.ProcessName.Equals(ProcessName)) | |
{ | |
pn.PName = g.ProcessName; | |
pn.PWinTitle = g.MainWindowTitle; | |
pn.PId = g.Id; | |
pn.PBsPri = g.BasePriority; | |
//pn.PExCod = g.ExitCode; | |
//pn.PExTim = g.ExitTime; | |
pn.PHwnd = g.Handle; | |
pn.PHwCnt = g.HandleCount; | |
pn.PHsExt = g.HasExited; | |
pn.PMscNm = g.MachineName; | |
pn.PMmFnm = g.MainModule.FileName; | |
pn.PMmFlVer = g.MainModule.FileVersionInfo; | |
pn.PMModMemSz = g.MainModule.ModuleMemorySize; | |
pn.PMmBsAdd = g.MainModule.BaseAddress; | |
pn.PMmEnPoAd = g.MainModule.EntryPointAddress; | |
pn.PMnMod = g.MainModule.ModuleName; | |
pn.PMnWinHw = g.MainWindowHandle; | |
pn.PMxWrkSt = g.MaxWorkingSet; | |
pn.PMinWrkSet = g.MinWorkingSet; | |
pn.PResp = g.Responding; | |
pn.PSsnId = g.SessionId; | |
pn.PThdCnt = g.Threads.Count; | |
pn.PToProTm = g.TotalProcessorTime; | |
pn.PUsrProTim = g.UserProcessorTime; | |
pn.PNonPgSysMemSiz = g.NonpagedSystemMemorySize64; | |
pn.PPgMemSiz = g.PagedMemorySize64; | |
pn.PPgSysMemSiz = g.PagedSystemMemorySize64; | |
pn.PPekPgMemSiz = g.PeakPagedMemorySize64; | |
pn.PPekVirMemSiz = g.PeakVirtualMemorySize64; | |
pn.PPekWrkSet = g.PeakWorkingSet64; | |
pn.PPriBooEnb = g.PriorityBoostEnabled; | |
pn.PPvtMemSiz = g.PrivateMemorySize64; | |
pn.PPrvProTim = g.PrivilegedProcessorTime; | |
pn.PProAff = g.ProcessorAffinity; | |
pn.PStrTime = g.StartTime; | |
pn.PVirMemSiz = g.VirtualMemorySize64; | |
pn.PWrkSet = g.WorkingSet64; | |
} | |
} | |
} | |
} | |
} |