System.Diagnostics.ProcessManager.GetProcessIds C# (CSharp) Method

GetProcessIds() public static method

Gets the IDs of all processes on the current machine.
public static GetProcessIds ( ) : int[]
return int[]
        public static int[] GetProcessIds()
        {
            throw new PlatformNotSupportedException();
        }

Same methods

ProcessManager::GetProcessIds ( string machineName ) : int[]

Usage Example

Example #1
0
        public static Process[] GetProcessesByName(string?processName, string machineName)
        {
            ProcessManager.ThrowIfRemoteMachine(machineName);

            int[] procIds   = ProcessManager.GetProcessIds();
            var   processes = new ArrayBuilder <Process>(string.IsNullOrEmpty(processName) ? procIds.Length : 0);

            // Iterate through all process IDs to load information about each process
            foreach (int pid in procIds)
            {
                ProcessInfo?processInfo = ProcessManager.CreateProcessInfo(pid, processName);
                if (processInfo != null)
                {
                    processes.Add(new Process(machineName, isRemoteMachine: false, pid, processInfo));
                }
            }

            return(processes.ToArray());
        }