2 using Microsoft.Win32.SafeHandles;
18 [MonitoringDescription(
"ProcessDesc")]
19 [DefaultEvent(
"Exited")]
20 [DefaultProperty(
"StartInfo")]
21 [Designer(
"System.Diagnostics.Design.ProcessDesigner, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
23 [HostProtection(
SecurityAction.LinkDemand, SharedState =
true, Synchronization =
true, ExternalProcessMgmt =
true, SelfAffectingProcessMgmt =
true)]
27 private enum StreamReadMode
43 HaveNtProcessInfo = 12
46 private bool haveProcessId;
48 private int processId;
50 private bool haveProcessHandle;
52 private SafeProcessHandle m_processHandle;
54 private bool isRemoteMachine;
56 private string machineName;
58 private ProcessInfo processInfo;
60 private int m_processAccess;
66 private bool haveMainWindow;
68 private IntPtr mainWindowHandle;
70 private string mainWindowTitle;
72 private bool haveWorkingSetLimits;
74 private IntPtr minWorkingSet;
76 private IntPtr maxWorkingSet;
78 private bool haveProcessorAffinity;
80 private IntPtr processorAffinity;
82 private bool havePriorityClass;
88 private bool watchForExit;
90 private bool watchingForExit;
98 private bool signaled;
102 private bool haveExitTime;
104 private bool responding;
106 private bool haveResponding;
108 private bool priorityBoostEnabled;
110 private bool havePriorityBoostEnabled;
112 private bool raisedOnExited;
128 private bool disposed;
130 private static object s_CreateProcessLock =
new object();
132 private StreamReadMode outputStreamReadMode;
134 private StreamReadMode errorStreamReadMode;
136 internal AsyncStreamReader output;
138 internal AsyncStreamReader error;
140 internal bool pendingOutputRead;
142 internal bool pendingErrorRead;
144 private static SafeFileHandle InvalidPipeHandle =
new SafeFileHandle(
IntPtr.
Zero, ownsHandle:
false);
150 [MonitoringDescription(
"ProcessAssociated")]
151 private bool Associated
157 return haveProcessHandle;
168 [MonitoringDescription(
"ProcessBasePriority")]
173 EnsureState(State.HaveProcessInfo);
174 return processInfo.basePriority;
184 [MonitoringDescription(
"ProcessExitCode")]
189 EnsureState(State.Exited);
202 [MonitoringDescription(
"ProcessTerminated")]
209 EnsureState(State.Associated);
210 SafeProcessHandle safeProcessHandle =
null;
213 safeProcessHandle = GetProcessHandle(1049600, throwIfExited:
false);
215 if (safeProcessHandle.IsInvalid)
219 else if (Microsoft.Win32.NativeMethods.GetExitCodeProcess(safeProcessHandle, out num) && num != 259)
228 ProcessWaitHandle processWaitHandle =
null;
231 processWaitHandle =
new ProcessWaitHandle(safeProcessHandle);
232 signaled = processWaitHandle.WaitOne(0, exitContext:
false);
236 processWaitHandle?.Close();
241 if (!Microsoft.Win32.NativeMethods.GetExitCodeProcess(safeProcessHandle, out num))
252 ReleaseProcessHandle(safeProcessHandle);
269 [MonitoringDescription(
"ProcessExitTime")]
276 EnsureState((State)20);
277 exitTime = GetProcessTimes().ExitTime;
290 [MonitoringDescription(
"ProcessHandle")]
295 EnsureState(State.Associated);
296 return OpenProcessHandle(m_processAccess).DangerousGetHandle();
308 EnsureState(State.Associated);
309 return OpenProcessHandle(m_processAccess);
317 [MonitoringDescription(
"ProcessHandleCount")]
322 EnsureState(State.HaveProcessInfo);
323 return processInfo.handleCount;
332 [MonitoringDescription(
"ProcessId")]
337 EnsureState(State.HaveId);
347 [MonitoringDescription(
"ProcessMachineName")]
352 EnsureState(State.Associated);
363 [MonitoringDescription(
"ProcessMainWindowHandle")]
370 EnsureState((State)3);
371 mainWindowHandle = ProcessManager.GetMainWindowHandle(processId);
372 if (mainWindowHandle != (
IntPtr)0)
374 haveMainWindow =
true;
378 EnsureState(State.HaveProcessInfo);
381 return mainWindowHandle;
391 [MonitoringDescription(
"ProcessMainWindowTitle")]
396 if (mainWindowTitle ==
null)
401 mainWindowTitle =
string.Empty;
405 int capacity = Microsoft.Win32.NativeMethods.GetWindowTextLength(
new HandleRef(
this, intPtr)) * 2;
407 Microsoft.Win32.NativeMethods.GetWindowText(
new HandleRef(
this, intPtr), stringBuilder, stringBuilder.
Capacity);
408 mainWindowTitle = stringBuilder.
ToString();
411 return mainWindowTitle;
423 [MonitoringDescription(
"ProcessMainModule")]
430 EnsureState((State)3);
431 ModuleInfo firstModuleInfo = NtProcessManager.GetFirstModuleInfo(processId);
435 EnsureState(State.HaveProcessInfo);
438 if (item.moduleInfo.Id == processInfo.mainModuleId)
455 [MonitoringDescription(
"ProcessMaxWorkingSet")]
460 EnsureWorkingSetLimits();
461 return maxWorkingSet;
465 SetWorkingSetLimits(
null, value);
477 [MonitoringDescription(
"ProcessMinWorkingSet")]
482 EnsureWorkingSetLimits();
483 return minWorkingSet;
487 SetWorkingSetLimits(value,
null);
499 [MonitoringDescription(
"ProcessModules")]
506 EnsureState((State)3);
507 ModuleInfo[] moduleInfos = ProcessManager.GetModuleInfos(processId);
509 for (
int i = 0; i < moduleInfos.Length; i++)
522 [Obsolete(
"This property has been deprecated. Please use System.Diagnostics.Process.NonpagedSystemMemorySize64 instead. http://go.microsoft.com/fwlink/?linkid=14202")]
524 [MonitoringDescription(
"ProcessNonpagedSystemMemorySize")]
529 EnsureState(State.HaveNtProcessInfo);
530 return (
int)processInfo.poolNonpagedBytes;
538 [MonitoringDescription(
"ProcessNonpagedSystemMemorySize")]
544 EnsureState(State.HaveNtProcessInfo);
545 return processInfo.poolNonpagedBytes;
552 [Obsolete(
"This property has been deprecated. Please use System.Diagnostics.Process.PagedMemorySize64 instead. http://go.microsoft.com/fwlink/?linkid=14202")]
554 [MonitoringDescription(
"ProcessPagedMemorySize")]
559 EnsureState(State.HaveNtProcessInfo);
560 return (
int)processInfo.pageFileBytes;
568 [MonitoringDescription(
"ProcessPagedMemorySize")]
574 EnsureState(State.HaveNtProcessInfo);
575 return processInfo.pageFileBytes;
582 [Obsolete(
"This property has been deprecated. Please use System.Diagnostics.Process.PagedSystemMemorySize64 instead. http://go.microsoft.com/fwlink/?linkid=14202")]
584 [MonitoringDescription(
"ProcessPagedSystemMemorySize")]
589 EnsureState(State.HaveNtProcessInfo);
590 return (
int)processInfo.poolPagedBytes;
598 [MonitoringDescription(
"ProcessPagedSystemMemorySize")]
604 EnsureState(State.HaveNtProcessInfo);
605 return processInfo.poolPagedBytes;
612 [Obsolete(
"This property has been deprecated. Please use System.Diagnostics.Process.PeakPagedMemorySize64 instead. http://go.microsoft.com/fwlink/?linkid=14202")]
614 [MonitoringDescription(
"ProcessPeakPagedMemorySize")]
619 EnsureState(State.HaveNtProcessInfo);
620 return (
int)processInfo.pageFileBytesPeak;
628 [MonitoringDescription(
"ProcessPeakPagedMemorySize")]
634 EnsureState(State.HaveNtProcessInfo);
635 return processInfo.pageFileBytesPeak;
642 [Obsolete(
"This property has been deprecated. Please use System.Diagnostics.Process.PeakWorkingSet64 instead. http://go.microsoft.com/fwlink/?linkid=14202")]
644 [MonitoringDescription(
"ProcessPeakWorkingSet")]
649 EnsureState(State.HaveNtProcessInfo);
650 return (
int)processInfo.workingSetPeak;
658 [MonitoringDescription(
"ProcessPeakWorkingSet")]
664 EnsureState(State.HaveNtProcessInfo);
665 return processInfo.workingSetPeak;
672 [Obsolete(
"This property has been deprecated. Please use System.Diagnostics.Process.PeakVirtualMemorySize64 instead. http://go.microsoft.com/fwlink/?linkid=14202")]
674 [MonitoringDescription(
"ProcessPeakVirtualMemorySize")]
679 EnsureState(State.HaveNtProcessInfo);
680 return (
int)processInfo.virtualBytesPeak;
688 [MonitoringDescription(
"ProcessPeakVirtualMemorySize")]
694 EnsureState(State.HaveNtProcessInfo);
695 return processInfo.virtualBytesPeak;
703 if (operatingSystem ==
null)
707 return operatingSystem;
719 [MonitoringDescription(
"ProcessPriorityBoostEnabled")]
724 EnsureState(State.IsNt);
725 if (!havePriorityBoostEnabled)
727 SafeProcessHandle handle =
null;
730 handle = GetProcessHandle(1024);
731 bool disabled =
false;
732 if (!Microsoft.Win32.NativeMethods.GetProcessPriorityBoost(handle, out disabled))
736 priorityBoostEnabled = !disabled;
737 havePriorityBoostEnabled =
true;
741 ReleaseProcessHandle(handle);
744 return priorityBoostEnabled;
748 EnsureState(State.IsNt);
749 SafeProcessHandle handle =
null;
752 handle = GetProcessHandle(512);
753 if (!Microsoft.Win32.NativeMethods.SetProcessPriorityBoost(handle, !value))
757 priorityBoostEnabled = value;
758 havePriorityBoostEnabled =
true;
762 ReleaseProcessHandle(handle);
775 [MonitoringDescription(
"ProcessPriorityClass")]
780 if (!havePriorityClass)
782 SafeProcessHandle handle =
null;
785 handle = GetProcessHandle(1024);
786 int num = Microsoft.Win32.NativeMethods.GetPriorityClass(handle);
792 havePriorityClass =
true;
796 ReleaseProcessHandle(handle);
799 return priorityClass;
811 SafeProcessHandle handle =
null;
814 handle = GetProcessHandle(512);
815 if (!Microsoft.Win32.NativeMethods.SetPriorityClass(handle, (
int)value))
819 priorityClass = value;
820 havePriorityClass =
true;
824 ReleaseProcessHandle(handle);
832 [Obsolete(
"This property has been deprecated. Please use System.Diagnostics.Process.PrivateMemorySize64 instead. http://go.microsoft.com/fwlink/?linkid=14202")]
834 [MonitoringDescription(
"ProcessPrivateMemorySize")]
839 EnsureState(State.HaveNtProcessInfo);
840 return (
int)processInfo.privateBytes;
848 [MonitoringDescription(
"ProcessPrivateMemorySize")]
854 EnsureState(State.HaveNtProcessInfo);
855 return processInfo.privateBytes;
864 [MonitoringDescription(
"ProcessPrivilegedProcessorTime")]
869 EnsureState(State.IsNt);
870 return GetProcessTimes().PrivilegedProcessorTime;
880 [MonitoringDescription(
"ProcessProcessName")]
885 EnsureState(State.HaveProcessInfo);
886 string processName = processInfo.processName;
887 if (processName.Length == 15 && ProcessManager.IsNt && ProcessManager.IsOSOlderThanXP && !isRemoteMachine)
892 if (moduleName !=
null)
901 return processInfo.processName;
912 [MonitoringDescription(
"ProcessProcessorAffinity")]
917 if (!haveProcessorAffinity)
919 SafeProcessHandle handle =
null;
922 handle = GetProcessHandle(1024);
923 if (!Microsoft.Win32.NativeMethods.GetProcessAffinityMask(handle, out
IntPtr processMask, out
IntPtr _))
927 processorAffinity = processMask;
931 ReleaseProcessHandle(handle);
933 haveProcessorAffinity =
true;
935 return processorAffinity;
939 SafeProcessHandle handle =
null;
942 handle = GetProcessHandle(512);
943 if (!Microsoft.Win32.NativeMethods.SetProcessAffinityMask(handle, value))
947 processorAffinity = value;
948 haveProcessorAffinity =
true;
952 ReleaseProcessHandle(handle);
964 [MonitoringDescription(
"ProcessResponding")]
991 [MonitoringDescription(
"ProcessSessionId")]
996 EnsureState(State.HaveNtProcessInfo);
997 return processInfo.sessionId;
1006 [MonitoringDescription(
"ProcessStartInfo")]
1011 if (startInfo ==
null)
1034 [MonitoringDescription(
"ProcessStartTime")]
1039 EnsureState(State.IsNt);
1040 return GetProcessTimes().StartTime;
1047 [DefaultValue(
null)]
1048 [MonitoringDescription(
"ProcessSynchronizingObject")]
1053 if (synchronizingObject ==
null && base.DesignMode)
1056 if (designerHost !=
null)
1065 return synchronizingObject;
1069 synchronizingObject = value;
1079 [MonitoringDescription(
"ProcessThreads")]
1084 if (threads ==
null)
1086 EnsureState(State.HaveProcessInfo);
1087 int count = processInfo.threadInfoList.Count;
1089 for (
int i = 0; i < count; i++)
1091 array[i] =
new ProcessThread(isRemoteMachine, (ThreadInfo)processInfo.threadInfoList[i]);
1104 [MonitoringDescription(
"ProcessTotalProcessorTime")]
1109 EnsureState(State.IsNt);
1110 return GetProcessTimes().TotalProcessorTime;
1119 [MonitoringDescription(
"ProcessUserProcessorTime")]
1124 EnsureState(State.IsNt);
1125 return GetProcessTimes().UserProcessorTime;
1132 [Obsolete(
"This property has been deprecated. Please use System.Diagnostics.Process.VirtualMemorySize64 instead. http://go.microsoft.com/fwlink/?linkid=14202")]
1134 [MonitoringDescription(
"ProcessVirtualMemorySize")]
1139 EnsureState(State.HaveNtProcessInfo);
1140 return (
int)processInfo.virtualBytes;
1148 [MonitoringDescription(
"ProcessVirtualMemorySize")]
1154 EnsureState(State.HaveNtProcessInfo);
1155 return processInfo.virtualBytes;
1163 [DefaultValue(
false)]
1164 [MonitoringDescription(
"ProcessEnableRaisingEvents")]
1169 return watchForExit;
1173 if (value == watchForExit)
1181 OpenProcessHandle();
1182 EnsureWatchingForExit();
1186 StopWatchingForExit();
1189 watchForExit = value;
1198 [MonitoringDescription(
"ProcessStandardInput")]
1203 if (standardInput ==
null)
1207 return standardInput;
1216 [MonitoringDescription(
"ProcessStandardOutput")]
1221 if (standardOutput ==
null)
1225 if (outputStreamReadMode == StreamReadMode.undefined)
1227 outputStreamReadMode = StreamReadMode.syncMode;
1229 else if (outputStreamReadMode != StreamReadMode.syncMode)
1233 return standardOutput;
1242 [MonitoringDescription(
"ProcessStandardError")]
1247 if (standardError ==
null)
1251 if (errorStreamReadMode == StreamReadMode.undefined)
1253 errorStreamReadMode = StreamReadMode.syncMode;
1255 else if (errorStreamReadMode != StreamReadMode.syncMode)
1259 return standardError;
1266 [Obsolete(
"This property has been deprecated. Please use System.Diagnostics.Process.WorkingSet64 instead. http://go.microsoft.com/fwlink/?linkid=14202")]
1268 [MonitoringDescription(
"ProcessWorkingSet")]
1273 EnsureState(State.HaveNtProcessInfo);
1274 return (
int)processInfo.workingSet;
1282 [MonitoringDescription(
"ProcessWorkingSet")]
1288 EnsureState(State.HaveNtProcessInfo);
1289 return processInfo.workingSet;
1295 [MonitoringDescription(
"ProcessAssociated")]
1300 [MonitoringDescription(
"ProcessAssociated")]
1304 [Category(
"Behavior")]
1305 [MonitoringDescription(
"ProcessExited")]
1322 outputStreamReadMode = StreamReadMode.undefined;
1323 errorStreamReadMode = StreamReadMode.undefined;
1324 m_processAccess = 2035711;
1327 private Process(
string machineName,
bool isRemoteMachine,
int processId, ProcessInfo processInfo)
1329 this.processInfo = processInfo;
1330 this.machineName = machineName;
1331 this.isRemoteMachine = isRemoteMachine;
1332 this.processId = processId;
1333 haveProcessId =
true;
1334 outputStreamReadMode = StreamReadMode.undefined;
1335 errorStreamReadMode = StreamReadMode.undefined;
1336 m_processAccess = 2035711;
1339 private ProcessThreadTimes GetProcessTimes()
1341 ProcessThreadTimes processThreadTimes =
new ProcessThreadTimes();
1342 SafeProcessHandle safeProcessHandle =
null;
1346 if (EnvironmentHelpers.IsWindowsVistaOrAbove())
1350 safeProcessHandle = GetProcessHandle(access, throwIfExited:
false);
1351 if (safeProcessHandle.IsInvalid)
1355 if (!Microsoft.Win32.NativeMethods.GetProcessTimes(safeProcessHandle, out processThreadTimes.create, out processThreadTimes.exit, out processThreadTimes.kernel, out processThreadTimes.user))
1359 return processThreadTimes;
1363 ReleaseProcessHandle(safeProcessHandle);
1379 int windowLong = Microsoft.Win32.NativeMethods.GetWindowLong(
new HandleRef(
this, intPtr), -16);
1380 if ((windowLong & 0x8000000) != 0)
1388 private void ReleaseProcessHandle(SafeProcessHandle handle)
1390 if (handle !=
null && (!haveProcessHandle || handle != m_processHandle))
1396 private void CompletionCallback(
object context,
bool wasSignaled)
1398 StopWatchingForExit();
1414 base.Dispose(disposing);
1423 if (haveProcessHandle)
1425 StopWatchingForExit();
1426 m_processHandle.Close();
1427 m_processHandle =
null;
1428 haveProcessHandle =
false;
1430 haveProcessId =
false;
1431 isRemoteMachine =
false;
1433 raisedOnExited =
false;
1434 standardOutput =
null;
1435 standardInput =
null;
1436 standardError =
null;
1443 private void EnsureState(State state)
1453 if ((state & State.Associated) != 0 && !Associated)
1455 throw new InvalidOperationException(SR.GetString(
"NoAssociatedProcess"));
1457 if ((state & State.HaveId) != 0 && !haveProcessId)
1459 if (!haveProcessHandle)
1461 EnsureState(State.Associated);
1462 throw new InvalidOperationException(SR.GetString(
"ProcessIdRequired"));
1464 SetProcessId(ProcessManager.GetProcessIdFromHandle(m_processHandle));
1466 if ((state & State.IsLocal) != 0 && isRemoteMachine)
1468 throw new NotSupportedException(SR.GetString(
"NotSupportedRemote"));
1470 if ((state & State.HaveProcessInfo) != 0 && processInfo ==
null)
1472 if ((state & State.HaveId) == (State)0)
1474 EnsureState(State.HaveId);
1476 ProcessInfo[] processInfos = ProcessManager.GetProcessInfos(machineName);
1477 for (
int i = 0; i < processInfos.Length; i++)
1479 if (processInfos[i].processId == processId)
1481 processInfo = processInfos[i];
1485 if (processInfo ==
null)
1487 throw new InvalidOperationException(SR.GetString(
"NoProcessInfo"));
1490 if ((state & State.Exited) != 0)
1494 throw new InvalidOperationException(SR.GetString(
"WaitTillExit"));
1496 if (!haveProcessHandle)
1498 throw new InvalidOperationException(SR.GetString(
"NoProcessHandle"));
1503 private void EnsureWatchingForExit()
1505 if (!watchingForExit)
1509 if (!watchingForExit)
1511 watchingForExit =
true;
1514 waitHandle =
new ProcessWaitHandle(m_processHandle);
1519 watchingForExit =
false;
1527 private void EnsureWorkingSetLimits()
1529 EnsureState(State.IsNt);
1530 if (!haveWorkingSetLimits)
1532 SafeProcessHandle handle =
null;
1535 handle = GetProcessHandle(1024);
1536 if (!Microsoft.Win32.NativeMethods.GetProcessWorkingSetSize(handle, out IntPtr min, out IntPtr max))
1540 minWorkingSet = min;
1541 maxWorkingSet = max;
1542 haveWorkingSetLimits =
true;
1546 ReleaseProcessHandle(handle);
1554 if (ProcessManager.IsNt)
1556 SetPrivilege(
"SeDebugPrivilege", 2);
1560 private static void SetPrivilege(
string privilegeName,
int attrib)
1563 Microsoft.Win32.NativeMethods.LUID lpLuid =
default(Microsoft.Win32.NativeMethods.LUID);
1564 IntPtr currentProcess = Microsoft.Win32.NativeMethods.GetCurrentProcess();
1565 if (!Microsoft.Win32.NativeMethods.OpenProcessToken(
new HandleRef(
null, currentProcess), 32, out TokenHandle))
1571 if (!Microsoft.Win32.NativeMethods.LookupPrivilegeValue(
null, privilegeName, out lpLuid))
1575 Microsoft.Win32.NativeMethods.TokenPrivileges tokenPrivileges =
new Microsoft.Win32.NativeMethods.TokenPrivileges();
1576 tokenPrivileges.Luid = lpLuid;
1577 tokenPrivileges.Attributes = attrib;
1578 Microsoft.Win32.NativeMethods.AdjustTokenPrivileges(
new HandleRef(
null, TokenHandle), DisableAllPrivileges:
false, tokenPrivileges, 0, IntPtr.Zero, IntPtr.Zero);
1586 Microsoft.Win32.SafeNativeMethods.CloseHandle(TokenHandle);
1593 if (ProcessManager.IsNt)
1595 SetPrivilege(
"SeDebugPrivilege", 0);
1608 if (!ProcessManager.IsProcessRunning(processId, machineName))
1612 return new Process(machineName, ProcessManager.IsRemoteMachine(machineName), processId,
null);
1645 if (processName ==
null)
1647 processName =
string.Empty;
1651 for (
int i = 0; i < processes.Length; i++)
1655 arrayList.
Add(processes[i]);
1663 arrayList.
CopyTo(array, 0);
1684 bool flag = ProcessManager.IsRemoteMachine(machineName);
1685 ProcessInfo[] processInfos = ProcessManager.GetProcessInfos(machineName);
1687 for (
int i = 0; i < processInfos.Length; i++)
1689 ProcessInfo processInfo = processInfos[i];
1690 array[i] =
new Process(machineName, flag, processInfo.processId, processInfo);
1699 return new Process(
".", isRemoteMachine:
false, Microsoft.Win32.NativeMethods.GetCurrentProcessId(),
null);
1706 if (eventHandler !=
null)
1723 private SafeProcessHandle GetProcessHandle(
int access,
bool throwIfExited)
1725 if (haveProcessHandle)
1729 ProcessWaitHandle processWaitHandle =
null;
1732 processWaitHandle =
new ProcessWaitHandle(m_processHandle);
1733 if (processWaitHandle.WaitOne(0, exitContext:
false))
1744 processWaitHandle?.Close();
1747 return m_processHandle;
1749 EnsureState((State)3);
1750 SafeProcessHandle invalidHandle = SafeProcessHandle.InvalidHandle;
1751 invalidHandle = ProcessManager.OpenProcess(processId, access, throwIfExited);
1752 if (throwIfExited && (access & 0x400) != 0 && Microsoft.Win32.NativeMethods.GetExitCodeProcess(invalidHandle, out exitCode) && exitCode != 259)
1756 return invalidHandle;
1759 private SafeProcessHandle GetProcessHandle(
int access)
1761 return GetProcessHandle(access, throwIfExited:
true);
1764 private SafeProcessHandle OpenProcessHandle()
1766 return OpenProcessHandle(2035711);
1769 private SafeProcessHandle OpenProcessHandle(
int access)
1771 if (!haveProcessHandle)
1775 throw new ObjectDisposedException(GetType().Name);
1777 SetProcessHandle(GetProcessHandle(access));
1779 return m_processHandle;
1782 private void RaiseOnExited()
1784 if (!raisedOnExited)
1788 if (!raisedOnExited)
1790 raisedOnExited =
true;
1803 mainWindowTitle =
null;
1806 haveMainWindow =
false;
1807 haveWorkingSetLimits =
false;
1808 haveProcessorAffinity =
false;
1809 havePriorityClass =
false;
1810 haveExitTime =
false;
1811 haveResponding =
false;
1812 havePriorityBoostEnabled =
false;
1815 private void SetProcessHandle(SafeProcessHandle processHandle)
1817 m_processHandle = processHandle;
1818 haveProcessHandle =
true;
1821 EnsureWatchingForExit();
1825 private void SetProcessId(
int processId)
1827 this.processId = processId;
1828 haveProcessId =
true;
1831 private void SetWorkingSetLimits(
object newMin,
object newMax)
1833 EnsureState(State.IsNt);
1834 SafeProcessHandle handle =
null;
1837 handle = GetProcessHandle(1280);
1838 if (!Microsoft.Win32.NativeMethods.GetProcessWorkingSetSize(handle, out IntPtr min, out IntPtr max))
1844 min = (IntPtr)newMin;
1848 max = (IntPtr)newMax;
1850 if ((
long)min > (long)max)
1854 throw new ArgumentException(SR.GetString(
"BadMinWorkset"));
1856 throw new ArgumentException(SR.GetString(
"BadMaxWorkset"));
1858 if (!Microsoft.Win32.NativeMethods.SetProcessWorkingSetSize(handle, min, max))
1862 if (!Microsoft.Win32.NativeMethods.GetProcessWorkingSetSize(handle, out min, out max))
1866 minWorkingSet = min;
1867 maxWorkingSet = max;
1868 haveWorkingSetLimits =
true;
1872 ReleaseProcessHandle(handle);
1886 if (processStartInfo.
FileName.Length == 0)
1892 return StartWithShellExecuteEx(processStartInfo);
1894 return StartWithCreateProcess(processStartInfo);
1897 private static void CreatePipeWithSecurityAttributes(out SafeFileHandle hReadPipe, out SafeFileHandle hWritePipe, Microsoft.Win32.NativeMethods.SECURITY_ATTRIBUTES lpPipeAttributes,
int nSize)
1899 if (!Microsoft.Win32.NativeMethods.CreatePipe(out hReadPipe, out hWritePipe, lpPipeAttributes, nSize) || hReadPipe.IsInvalid || hWritePipe.IsInvalid)
1905 private void CreatePipe(out SafeFileHandle parentHandle, out SafeFileHandle childHandle,
bool parentInputs)
1907 Microsoft.Win32.NativeMethods.SECURITY_ATTRIBUTES sECURITY_ATTRIBUTES =
new Microsoft.Win32.NativeMethods.SECURITY_ATTRIBUTES();
1908 sECURITY_ATTRIBUTES.bInheritHandle =
true;
1909 SafeFileHandle hWritePipe =
null;
1914 CreatePipeWithSecurityAttributes(out childHandle, out hWritePipe, sECURITY_ATTRIBUTES, 0);
1918 CreatePipeWithSecurityAttributes(out hWritePipe, out childHandle, sECURITY_ATTRIBUTES, 0);
1920 if (!Microsoft.Win32.NativeMethods.DuplicateHandle(
new HandleRef(
this, Microsoft.Win32.NativeMethods.GetCurrentProcess()), hWritePipe,
new HandleRef(
this, Microsoft.Win32.NativeMethods.GetCurrentProcess()), out parentHandle, 0, bInheritHandle:
false, 2))
1927 if (hWritePipe !=
null && !hWritePipe.IsInvalid)
1934 private static StringBuilder BuildCommandLine(
string executableFileName,
string arguments)
1937 string text = executableFileName.Trim();
1941 stringBuilder.
Append(
"\"");
1943 stringBuilder.
Append(text);
1946 stringBuilder.
Append(
"\"");
1948 if (!
string.IsNullOrEmpty(arguments))
1950 stringBuilder.
Append(
" ");
1951 stringBuilder.
Append(arguments);
1953 return stringBuilder;
1956 private bool StartWithCreateProcess(ProcessStartInfo startInfo)
1958 if (startInfo.StandardOutputEncoding !=
null && !startInfo.RedirectStandardOutput)
1960 throw new InvalidOperationException(SR.GetString(
"StandardOutputEncodingNotAllowed"));
1962 if (startInfo.StandardErrorEncoding !=
null && !startInfo.RedirectStandardError)
1964 throw new InvalidOperationException(SR.GetString(
"StandardErrorEncodingNotAllowed"));
1968 throw new ObjectDisposedException(GetType().Name);
1970 StringBuilder stringBuilder = BuildCommandLine(startInfo.FileName, startInfo.Arguments);
1971 Microsoft.Win32.NativeMethods.STARTUPINFO sTARTUPINFO =
new Microsoft.Win32.NativeMethods.STARTUPINFO();
1972 Microsoft.Win32.SafeNativeMethods.PROCESS_INFORMATION pROCESS_INFORMATION =
new Microsoft.Win32.SafeNativeMethods.PROCESS_INFORMATION();
1973 SafeProcessHandle safeProcessHandle =
new SafeProcessHandle();
1974 Microsoft.Win32.SafeHandles.SafeThreadHandle safeThreadHandle =
new Microsoft.Win32.SafeHandles.SafeThreadHandle();
1976 SafeFileHandle parentHandle =
null;
1977 SafeFileHandle parentHandle2 =
null;
1978 SafeFileHandle parentHandle3 =
null;
1980 lock (s_CreateProcessLock)
1984 if (startInfo.RedirectStandardInput || startInfo.RedirectStandardOutput || startInfo.RedirectStandardError)
1986 if (startInfo.RedirectStandardInput)
1988 CreatePipe(out parentHandle, out sTARTUPINFO.hStdInput, parentInputs:
true);
1992 sTARTUPINFO.hStdInput =
new SafeFileHandle(Microsoft.Win32.NativeMethods.GetStdHandle(-10), ownsHandle:
false);
1994 if (startInfo.RedirectStandardOutput)
1996 CreatePipe(out parentHandle2, out sTARTUPINFO.hStdOutput, parentInputs:
false);
2000 sTARTUPINFO.hStdOutput =
new SafeFileHandle(Microsoft.Win32.NativeMethods.GetStdHandle(-11), ownsHandle:
false);
2002 if (startInfo.RedirectStandardError)
2004 CreatePipe(out parentHandle3, out sTARTUPINFO.hStdError, parentInputs:
false);
2008 sTARTUPINFO.hStdError =
new SafeFileHandle(Microsoft.Win32.NativeMethods.GetStdHandle(-12), ownsHandle:
false);
2010 sTARTUPINFO.dwFlags = 256;
2013 if (startInfo.CreateNoWindow)
2017 IntPtr intPtr = (IntPtr)0;
2018 if (startInfo.environmentVariables !=
null)
2020 bool unicode =
false;
2021 if (ProcessManager.IsNt)
2026 byte[] value = EnvironmentBlock.ToByteArray(startInfo.environmentVariables, unicode);
2030 string text = startInfo.WorkingDirectory;
2031 if (text ==
string.Empty)
2033 text = Environment.CurrentDirectory;
2035 if (startInfo.UserName.Length != 0)
2037 if (startInfo.Password !=
null && startInfo.PasswordInClearText !=
null)
2039 throw new ArgumentException(SR.GetString(
"CantSetDuplicatePassword"));
2041 Microsoft.Win32.NativeMethods.LogonFlags logonFlags = (Microsoft.Win32.NativeMethods.LogonFlags)0;
2042 if (startInfo.LoadUserProfile)
2044 logonFlags = Microsoft.Win32.NativeMethods.LogonFlags.LOGON_WITH_PROFILE;
2046 IntPtr intPtr2 = IntPtr.Zero;
2057 flag = Microsoft.Win32.NativeMethods.CreateProcessWithLogonW(startInfo.UserName, startInfo.Domain, intPtr2, logonFlags,
null, stringBuilder, num2, intPtr, text, sTARTUPINFO, pROCESS_INFORMATION);
2062 if (pROCESS_INFORMATION.hProcess != (IntPtr)0 && pROCESS_INFORMATION.hProcess != Microsoft.Win32.NativeMethods.INVALID_HANDLE_VALUE)
2064 safeProcessHandle.InitialSetHandle(pROCESS_INFORMATION.hProcess);
2066 if (pROCESS_INFORMATION.hThread != (IntPtr)0 && pROCESS_INFORMATION.hThread != Microsoft.Win32.NativeMethods.INVALID_HANDLE_VALUE)
2068 safeThreadHandle.InitialSetHandle(pROCESS_INFORMATION.hThread);
2073 if (num == 193 || num == 216)
2075 throw new Win32Exception(num, SR.GetString(
"InvalidApplication"));
2082 if (intPtr2 != IntPtr.Zero)
2097 flag = Microsoft.Win32.NativeMethods.CreateProcess(
null, stringBuilder,
null,
null, bInheritHandles:
true, num2, intPtr, text, sTARTUPINFO, pROCESS_INFORMATION);
2102 if (pROCESS_INFORMATION.hProcess != (IntPtr)0 && pROCESS_INFORMATION.hProcess != Microsoft.Win32.NativeMethods.INVALID_HANDLE_VALUE)
2104 safeProcessHandle.InitialSetHandle(pROCESS_INFORMATION.hProcess);
2106 if (pROCESS_INFORMATION.hThread != (IntPtr)0 && pROCESS_INFORMATION.hThread != Microsoft.Win32.NativeMethods.INVALID_HANDLE_VALUE)
2108 safeThreadHandle.InitialSetHandle(pROCESS_INFORMATION.hThread);
2113 if (num == 193 || num == 216)
2115 throw new Win32Exception(num, SR.GetString(
"InvalidApplication"));
2127 sTARTUPINFO.Dispose();
2130 if (startInfo.RedirectStandardInput)
2135 if (startInfo.RedirectStandardOutput)
2137 Encoding encoding = (startInfo.StandardOutputEncoding !=
null) ? startInfo.StandardOutputEncoding : Console.OutputEncoding;
2138 standardOutput =
new StreamReader(
new FileStream(parentHandle2,
FileAccess.Read, 4096, isAsync:
false), encoding, detectEncodingFromByteOrderMarks:
true, 4096);
2140 if (startInfo.RedirectStandardError)
2142 Encoding encoding2 = (startInfo.StandardErrorEncoding !=
null) ? startInfo.StandardErrorEncoding : Console.OutputEncoding;
2143 standardError =
new StreamReader(
new FileStream(parentHandle3,
FileAccess.Read, 4096, isAsync:
false), encoding2, detectEncodingFromByteOrderMarks:
true, 4096);
2145 bool result =
false;
2146 if (!safeProcessHandle.IsInvalid)
2148 SetProcessHandle(safeProcessHandle);
2149 SetProcessId(pROCESS_INFORMATION.dwProcessId);
2150 safeThreadHandle.Close();
2156 private bool StartWithShellExecuteEx(ProcessStartInfo startInfo)
2160 throw new ObjectDisposedException(GetType().Name);
2162 if (!
string.IsNullOrEmpty(startInfo.UserName) || startInfo.Password !=
null)
2164 throw new InvalidOperationException(SR.GetString(
"CantStartAsUser"));
2166 if (startInfo.RedirectStandardInput || startInfo.RedirectStandardOutput || startInfo.RedirectStandardError)
2168 throw new InvalidOperationException(SR.GetString(
"CantRedirectStreams"));
2170 if (startInfo.StandardErrorEncoding !=
null)
2172 throw new InvalidOperationException(SR.GetString(
"StandardErrorEncodingNotAllowed"));
2174 if (startInfo.StandardOutputEncoding !=
null)
2176 throw new InvalidOperationException(SR.GetString(
"StandardOutputEncodingNotAllowed"));
2178 if (startInfo.environmentVariables !=
null)
2180 throw new InvalidOperationException(SR.GetString(
"CantUseEnvVars"));
2182 Microsoft.Win32.NativeMethods.ShellExecuteInfo shellExecuteInfo =
new Microsoft.Win32.NativeMethods.ShellExecuteInfo();
2183 shellExecuteInfo.fMask = 64;
2184 if (startInfo.ErrorDialog)
2186 shellExecuteInfo.hwnd = startInfo.ErrorDialogParentHandle;
2190 shellExecuteInfo.fMask |= 1024;
2192 switch (startInfo.WindowStyle)
2195 shellExecuteInfo.nShow = 0;
2198 shellExecuteInfo.nShow = 2;
2201 shellExecuteInfo.nShow = 3;
2204 shellExecuteInfo.nShow = 1;
2209 if (startInfo.FileName.Length != 0)
2213 if (startInfo.Verb.Length != 0)
2217 if (startInfo.Arguments.Length != 0)
2221 if (startInfo.WorkingDirectory.Length != 0)
2225 shellExecuteInfo.fMask |= 256;
2226 ShellExecuteHelper shellExecuteHelper =
new ShellExecuteHelper(shellExecuteInfo);
2228 if (!shellExecuteHelper.ShellExecuteOnSTAThread())
2230 num = shellExecuteHelper.ErrorCode;
2233 long num2 = (long)shellExecuteInfo.hInstApp;
2234 long num3 = num2 - 2;
2235 if ((ulong)num3 <= 6uL)
2253 long num4 = num2 - 26;
2254 if ((ulong)num4 > 6uL)
2288 num = (int)shellExecuteInfo.hInstApp;
2300 if (num == 193 || num == 216)
2302 throw new Win32Exception(num, SR.GetString(
"InvalidApplication"));
2312 if (shellExecuteInfo.lpFile != (IntPtr)0)
2316 if (shellExecuteInfo.lpVerb != (IntPtr)0)
2320 if (shellExecuteInfo.lpParameters != (IntPtr)0)
2324 if (shellExecuteInfo.lpDirectory != (IntPtr)0)
2329 if (shellExecuteInfo.hProcess != (IntPtr)0)
2331 SafeProcessHandle processHandle =
new SafeProcessHandle(shellExecuteInfo.hProcess);
2332 SetProcessHandle(processHandle);
2352 processStartInfo.
UserName = userName;
2353 processStartInfo.
Password = password;
2354 processStartInfo.
Domain = domain;
2356 return Start(processStartInfo);
2374 processStartInfo.
UserName = userName;
2375 processStartInfo.
Password = password;
2376 processStartInfo.
Domain = domain;
2378 return Start(processStartInfo);
2416 if (startInfo ==
null)
2421 if (process.
Start())
2434 SafeProcessHandle safeProcessHandle =
null;
2437 safeProcessHandle = GetProcessHandle(1);
2438 if (!Microsoft.Win32.NativeMethods.TerminateProcess(safeProcessHandle, -1))
2445 ReleaseProcessHandle(safeProcessHandle);
2449 private void StopWatchingForExit()
2451 if (watchingForExit)
2455 if (watchingForExit)
2457 watchingForExit =
false;
2461 registeredWaitHandle =
null;
2475 string text =
string.Empty;
2483 if (text.Length != 0)
2491 return base.ToString();
2493 return base.ToString();
2504 SafeProcessHandle safeProcessHandle =
null;
2505 ProcessWaitHandle processWaitHandle =
null;
2509 safeProcessHandle = GetProcessHandle(1048576, throwIfExited:
false);
2510 if (safeProcessHandle.IsInvalid)
2516 processWaitHandle =
new ProcessWaitHandle(safeProcessHandle);
2517 if (processWaitHandle.WaitOne(milliseconds, exitContext:
false))
2531 processWaitHandle?.Close();
2532 if (output !=
null && milliseconds == -1)
2534 output.WaitUtilEOF();
2536 if (error !=
null && milliseconds == -1)
2538 error.WaitUtilEOF();
2540 ReleaseProcessHandle(safeProcessHandle);
2542 if (flag && watchForExit)
2564 SafeProcessHandle handle =
null;
2567 handle = GetProcessHandle(1049600);
2568 switch (Microsoft.Win32.NativeMethods.WaitForInputIdle(handle, milliseconds))
2580 ReleaseProcessHandle(handle);
2598 if (outputStreamReadMode == StreamReadMode.undefined)
2600 outputStreamReadMode = StreamReadMode.asyncMode;
2602 else if (outputStreamReadMode != StreamReadMode.asyncMode)
2606 if (pendingOutputRead)
2610 pendingOutputRead =
true;
2613 if (standardOutput ==
null)
2618 output =
new AsyncStreamReader(
this, baseStream, OutputReadNotifyUser, standardOutput.
CurrentEncoding);
2620 output.BeginReadLine();
2628 if (errorStreamReadMode == StreamReadMode.undefined)
2630 errorStreamReadMode = StreamReadMode.asyncMode;
2632 else if (errorStreamReadMode != StreamReadMode.asyncMode)
2636 if (pendingErrorRead)
2640 pendingErrorRead =
true;
2643 if (standardError ==
null)
2648 error =
new AsyncStreamReader(
this, baseStream, ErrorReadNotifyUser, standardError.
CurrentEncoding);
2650 error.BeginReadLine();
2660 output.CancelOperation();
2661 pendingOutputRead =
false;
2674 error.CancelOperation();
2675 pendingErrorRead =
false;
2681 internal void OutputReadNotifyUser(
string data)
2684 if (outputDataReceived !=
null)
2692 dataReceivedEventArgs
2697 outputDataReceived(
this, dataReceivedEventArgs);
2702 internal void ErrorReadNotifyUser(
string data)
2705 if (errorDataReceived !=
null)
2707 DataReceivedEventArgs dataReceivedEventArgs =
new DataReceivedEventArgs(data);
2713 dataReceivedEventArgs
2718 errorDataReceived(
this, dataReceivedEventArgs);
Represents a character encoding.To browse the .NET Framework source code for this type,...
static void EnterDebugMode()
Puts a T:System.Diagnostics.Process component in state to interact with operating system processes th...
ProcessModule MainModule
Gets the main module for the associated process.
static Process Start(string fileName, string userName, SecureString password, string domain)
Starts a process resource by specifying the name of an application, a user name, a password,...
bool EnableRaisingEvents
Gets or sets whether the E:System.Diagnostics.Process.Exited event should be raised when the process ...
DateTime StartTime
Gets the time that the associated process was started.
PlatformID
Identifies the operating system, or platform, supported by an assembly.
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
static Process Start(string fileName)
Starts a process resource by specifying the name of a document or application file and associates the...
static Process Start(string fileName, string arguments, string userName, SecureString password, string domain)
Starts a process resource by specifying the name of an application, a set of command-line arguments,...
TimeSpan UserProcessorTime
Gets the user processor time for this process.
int ExitCode
Gets the value that the associated process specified when it terminated.
DataReceivedEventHandler ErrorDataReceived
Occurs when an application writes to its redirected P:System.Diagnostics.Process.StandardError stream...
IComponent RootComponent
Gets the instance of the base class used as the root component for the current design.
Encapsulates operating system–specific objects that wait for exclusive access to shared resources.
Represents a handle that has been registered when calling M:System.Threading.ThreadPool....
static void FreeHGlobal(IntPtr hglobal)
Frees memory previously allocated from the unmanaged memory of the process.
unsafe override string ToString()
Converts the value of this instance to a T:System.String.
Represents an operating system process thread.
void Refresh()
Discards any information about the associated process that has been cached inside the process compone...
long VirtualMemorySize64
Gets the amount of the virtual memory, in bytes, allocated for the associated process.
Process()
Initializes a new instance of the T:System.Diagnostics.Process class.
static IntPtr SecureStringToCoTaskMemUnicode(SecureString s)
Copies the contents of a managed T:System.Security.SecureString object to a block of memory allocated...
static Process [] GetProcessesByName(string processName)
Creates an array of new T:System.Diagnostics.Process components and associates them with all the proc...
int HandleCount
Gets the number of handles opened by the process.
StringComparison
Specifies the culture, case, and sort rules to be used by certain overloads of the M:System....
Provides a strongly typed collection of T:System.Diagnostics.ProcessThread objects.
bool WaitForInputIdle()
Causes the T:System.Diagnostics.Process component to wait indefinitely for the associated process to ...
string MainWindowTitle
Gets the caption of the main window of the process.
void WaitForExit()
Instructs the T:System.Diagnostics.Process component to wait indefinitely for the associated process ...
long PeakWorkingSet64
Gets the maximum amount of physical memory, in bytes, used by the associated process.
string MachineName
Gets the name of the computer the associated process is running on.
long PeakVirtualMemorySize64
Gets the maximum amount of virtual memory, in bytes, used by the associated process.
virtual int Count
Gets the number of elements actually contained in the T:System.Collections.ArrayList.
ProcessThreadCollection Threads
Gets the set of threads that are running in the associated process.
static OperatingSystem OSVersion
Gets an T:System.OperatingSystem object that contains the current platform identifier and version num...
bool UseShellExecute
Gets or sets a value indicating whether to use the operating system shell to start the process.
Wraps a managed object holding a handle to a resource that is passed to unmanaged code using platform...
Implements a T:System.IO.TextReader that reads characters from a byte stream in a particular encoding...
static void LeaveDebugMode()
Takes a T:System.Diagnostics.Process component out of the state that lets it interact with operating ...
Represents an instant in time, typically expressed as a date and time of day. To browse the ....
Provides a way to synchronously or asynchronously execute a delegate.
void BeginOutputReadLine()
Begins asynchronous read operations on the redirected P:System.Diagnostics.Process....
static string GetFileName(string path)
Returns the file name and extension of the specified path string.
Represents the base class for classes that contain event data, and provides a value to use for events...
DateTime ExitTime
Gets the time that the associated process exited.
Provides a strongly typed collection of T:System.Diagnostics.ProcessModule objects.
static Delegate Remove(Delegate source, Delegate value)
Removes the last occurrence of the invocation list of a delegate from the invocation list of another ...
DataReceivedEventHandler OutputDataReceived
Occurs each time an application writes a line to its redirected P:System.Diagnostics....
static Delegate Combine(Delegate a, Delegate b)
Concatenates the invocation lists of two delegates.
static Process [] GetProcesses(string machineName)
Creates a new T:System.Diagnostics.Process component for each process resource on the specified compu...
Version Version
Gets a T:System.Version object that identifies the operating system.
StreamReader StandardError
Gets a stream used to read the error output of the application.
ProcessWindowStyle
Specified how a new window should appear when the system starts a process.
ProcessStartInfo StartInfo
Gets or sets the properties to pass to the M:System.Diagnostics.Process.Start method of the T:System....
Represents a wrapper class for operating system handles. This class must be inherited.
Specifies a set of values that are used when you start a process.
bool InvokeRequired
Gets a value indicating whether the caller must call M:System.ComponentModel.ISynchronizeInvoke....
long PagedSystemMemorySize64
Gets the amount of pageable system memory, in bytes, allocated for the associated process.
PlatformID Platform
Gets a T:System.PlatformID enumeration value that identifies the operating system platform.
int PagedMemorySize
Gets the amount of paged memory, in bytes, allocated for the associated process.
Represents a.dll or .exe file that is loaded into a particular process.
int PeakVirtualMemorySize
Gets the maximum amount of virtual memory, in bytes, used by the associated process.
int NonpagedSystemMemorySize
Gets the amount of nonpaged system memory, in bytes, allocated for the associated process.
bool IsAllocated
Gets a value indicating whether the handle is allocated.
The exception thrown when using invalid arguments that are enumerators.
SecurityAction
Specifies the security actions that can be performed using declarative security.
Implements a T:System.IO.TextWriter for writing characters to a stream in a particular encoding....
IntPtr MaxWorkingSet
Gets or sets the maximum allowable working set size, in bytes, for the associated process.
static Process [] GetProcessesByName(string processName, string machineName)
Creates an array of new T:System.Diagnostics.Process components and associates them with all the proc...
Provides information about, and means to manipulate, the current environment and platform....
static bool IsDefined(Type enumType, object value)
Returns an indication whether a constant with a specified value exists in a specified enumeration.
IntPtr MinWorkingSet
Gets or sets the minimum allowable working set size, in bytes, for the associated process.
delegate void DataReceivedEventHandler(object sender, DataReceivedEventArgs e)
Represents the method that will handle the E:System.Diagnostics.Process.OutputDataReceived event or E...
static readonly EventArgs Empty
Provides a value to use with events that do not have event data.
ISynchronizeInvoke SynchronizingObject
Gets or sets the object used to marshal the event handler calls that are issued as a result of a proc...
EventHandler Exited
Occurs when a process exits.
StringBuilder Append(char value, int repeatCount)
Appends a specified number of copies of the string representation of a Unicode character to this inst...
bool CloseMainWindow()
Closes a process that has a user interface by sending a close message to its main window.
static RegisteredWaitHandle RegisterWaitForSingleObject(WaitHandle waitObject, WaitOrTimerCallback callBack, object state, uint millisecondsTimeOutInterval, bool executeOnlyOnce)
Registers a delegate to wait for a T:System.Threading.WaitHandle, specifying a 32-bit unsigned intege...
string UserName
Gets or sets the user name to be used when starting the process.
bool? HasExited
Gets a value indicating whether the associated process has been terminated.
int Major
Gets the value of the major component of the version number for the current T:System....
Represents a collection that can contain many different types of permissions.
string ProcessName
Gets the name of the process.
Throws an exception for a Win32 error code.
Provides the base class for enumerations.
TimeSpan PrivilegedProcessorTime
Gets the privileged processor time for this process.
string ModuleName
Gets the name of the process module.
int PrivateMemorySize
Gets the amount of private memory, in bytes, allocated for the associated process.
delegate void EventHandler(object sender, EventArgs e)
Represents the method that will handle an event that has no event data.
virtual Stream BaseStream
Returns the underlying stream.
Provides a T:System.IO.Stream for a file, supporting both synchronous and asynchronous read and write...
StreamWriter StandardInput
Gets a stream used to write the input of the application.
bool PriorityBoostEnabled
Gets or sets a value indicating whether the associated process priority should temporarily be boosted...
Represents text that should be kept confidential, such as by deleting it from computer memory when no...
string FileName
Gets or sets the application or document to start.
long PrivateMemorySize64
Gets the amount of private memory, in bytes, allocated for the associated process.
StreamReader StandardOutput
Gets a stream used to read the textual output of the application.
A platform-specific type that is used to represent a pointer or a handle.
ProcessPriorityClass PriorityClass
Gets or sets the overall priority category for the associated process.
Provides access to local and remote processes and enables you to start and stop local system processe...
static void PrepareConstrainedRegions()
Designates a body of code as a constrained execution region (CER).
Provides the base implementation for the T:System.ComponentModel.IComponent interface and enables obj...
Represents a delegate, which is a data structure that refers to a static method or to a class instanc...
static GCHandle Alloc(object value)
Allocates a F:System.Runtime.InteropServices.GCHandleType.Normal handle for the specified object.
Provides a collection of methods for allocating unmanaged memory, copying unmanaged memory blocks,...
GCHandleType
Represents the types of handles the T:System.Runtime.InteropServices.GCHandle class can allocate.
override string ToString()
Formats the process's name as a string, combined with the parent component type, if applicable.
int VirtualMemorySize
Gets the size of the process's virtual memory, in bytes.
Provides a way to access a managed object from unmanaged memory.
IntPtr AddrOfPinnedObject()
Retrieves the address of an object in a F:System.Runtime.InteropServices.GCHandleType....
long WorkingSet64
Gets the amount of physical memory, in bytes, allocated for the associated process.
virtual void CopyTo(Array array)
Copies the entire T:System.Collections.ArrayList to a compatible one-dimensional T:System....
override void Dispose(bool disposing)
Release all resources used by this process.
static Process GetProcessById(int processId)
Returns a new T:System.Diagnostics.Process component, given the identifier of a process on the local ...
Provides data for the E:System.Diagnostics.Process.OutputDataReceived and E:System....
static unsafe IntPtr StringToCoTaskMemUni(string s)
Copies the contents of a managed T:System.String to a block of memory allocated from the unmanaged CO...
virtual void Close()
Releases all resources held by the current T:System.Threading.WaitHandle.
int BasePriority
Gets the base priority of the associated process.
int PagedSystemMemorySize
Gets the amount of pageable system memory, in bytes, allocated for the associated process.
Provides a multilevel switch to control tracing and debug output without recompiling your code.
virtual bool AutoFlush
Gets or sets a value indicating whether the T:System.IO.StreamWriter will flush its buffer to the und...
void Kill()
Immediately stops the associated process.
Represents a mutable string of characters. This class cannot be inherited.To browse the ....
virtual int Add(object value)
Adds an object to the end of the T:System.Collections.ArrayList.
IntPtr ProcessorAffinity
Gets or sets the processors on which the threads in this process can be scheduled to run.
int WorkingSet
Gets the associated process's physical memory usage, in bytes.
virtual object GetService(Type service)
Returns an object that represents a service provided by the T:System.ComponentModel....
Represents information about an operating system, such as the version and platform identifier....
int PeakPagedMemorySize
Gets the maximum amount of memory in the virtual memory paging file, in bytes, used by the associated...
bool WaitForInputIdle(int milliseconds)
Causes the T:System.Diagnostics.Process component to wait the specified number of milliseconds for th...
void OnExited()
Raises the E:System.Diagnostics.Process.Exited event.
void Close()
Frees all the resources that are associated with this component.
static CultureInfo CurrentCulture
Gets or sets the T:System.Globalization.CultureInfo object that represents the culture used by the cu...
The exception that is thrown when one of the arguments provided to a method is not valid.
void Free()
Releases a T:System.Runtime.InteropServices.GCHandle.
void CancelErrorRead()
Cancels the asynchronous read operation on the redirected P:System.Diagnostics.Process....
long PagedMemorySize64
Gets the amount of paged memory, in bytes, allocated for the associated process.
SecureString Password
Gets or sets a secure string that contains the user password to use when starting the process.
int Capacity
Gets or sets the maximum number of characters that can be contained in the memory allocated by the cu...
static void ZeroFreeCoTaskMemUnicode(IntPtr s)
Frees an unmanaged string pointer that was allocated using the M:System.Runtime.InteropServices....
TimeSpan TotalProcessorTime
Gets the total processor time for this process.
int Id
Gets the unique identifier for the associated process.
static Process GetProcessById(int processId, string machineName)
Returns a new T:System.Diagnostics.Process component, given a process identifier and the name of a co...
Represents errors that occur during application execution.To browse the .NET Framework source code fo...
DesignerSerializationVisibility
Specifies the visibility a property has to the design-time serializer.
FileAccess
Defines constants for read, write, or read/write access to a file.
static readonly IntPtr Zero
A read-only field that represents a pointer or handle that has been initialized to zero.
static Process Start(string fileName, string arguments)
Starts a process resource by specifying the name of an application and a set of command-line argument...
virtual Encoding CurrentEncoding
Gets the current character encoding that the current T:System.IO.StreamReader object is using.
Represents a time interval.To browse the .NET Framework source code for this type,...
IntPtr MainWindowHandle
Gets the window handle of the main window of the associated process.
Provides an interface for managing designer transactions and components.
static IntPtr StringToHGlobalAuto(string s)
Copies the contents of a managed T:System.String into unmanaged memory, converting into ANSI format i...
static Process Start(ProcessStartInfo startInfo)
Starts the process resource that is specified by the parameter containing process start information (...
The exception that is thrown when a method call is invalid for the object's current state.
int PeakWorkingSet
Gets the peak working set size for the associated process, in bytes.
IAsyncResult BeginInvoke(Delegate method, object[] args)
Asynchronously executes the delegate on the thread that created this object.
bool Start()
Starts (or reuses) the process resource that is specified by the P:System.Diagnostics....
static Process GetCurrentProcess()
Gets a new T:System.Diagnostics.Process component and associates it with the currently active process...
long NonpagedSystemMemorySize64
Gets the amount of nonpaged system memory, in bytes, allocated for the associated process.
void BeginErrorReadLine()
Begins asynchronous read operations on the redirected P:System.Diagnostics.Process....
object Invoke(Delegate method, object[] args)
Synchronously executes the delegate on the thread that created this object and marshals the call to t...
Provides information about a specific culture (called a locale for unmanaged code development)....
ProcessModuleCollection Modules
Gets the modules that have been loaded by the associated process.
int SessionId
Gets the Terminal Services session identifier for the associated process.
IntPtr Handle
Gets the native handle of the associated process.
static int GetLastWin32Error()
Returns the error code returned by the last unmanaged function that was called using platform invoke ...
string Domain
Gets or sets a value that identifies the domain to use when starting the process.
bool Responding
Gets a value indicating whether the user interface of the process is responding.
long PeakPagedMemorySize64
Gets the maximum amount of memory in the virtual memory paging file, in bytes, used by the associated...
static Process [] GetProcesses()
Creates a new T:System.Diagnostics.Process component for each process resource on the local computer.
Performs operations on T:System.String instances that contain file or directory path information....
bool WaitForExit(int milliseconds)
Instructs the T:System.Diagnostics.Process component to wait the specified number of milliseconds for...
void CancelOutputRead()
Cancels the asynchronous read operation on the redirected P:System.Diagnostics.Process....
ProcessPriorityClass
Indicates the priority that the system associates with a process. This value, together with the prior...
Provides a pool of threads that can be used to execute tasks, post work items, process asynchronous I...
Provides a set of static methods and properties that provide support for compilers....
bool Unregister(WaitHandle waitObject)
Cancels a registered wait operation issued by the M:System.Threading.ThreadPool.RegisterWaitForSingle...
Implements the T:System.Collections.IList interface using an array whose size is dynamically increase...
Provides a generic view of a sequence of bytes. This is an abstract class.To browse the ....
static string ChangeExtension(string path, string extension)
Changes the extension of a path string.