예제 #1
0
        /// <summary>Gets the process name for the specified process ID on the specified machine.</summary>
        /// <param name="processId">The process ID.</param>
        /// <param name="machineName">The machine name.</param>
        /// <returns>The process name for the process if it could be found; otherwise, null.</returns>
        public static string?GetProcessName(int processId, string machineName)
        {
            if (IsRemoteMachine(machineName))
            {
                // remote case: we take the hit of looping through all results
                ProcessInfo[] processInfos = NtProcessManager.GetProcessInfos(machineName, isRemoteMachine: true);
                foreach (ProcessInfo processInfo in processInfos)
                {
                    if (processInfo.ProcessId == processId)
                    {
                        return(processInfo.ProcessName);
                    }
                }
            }
            else
            {
                // local case: do not use performance counter and also attempt to get the matching (by pid) process only

                string?processName = Interop.Kernel32.GetProcessName((uint)processId);
                if (processName is not null)
                {
                    return(NtProcessInfoHelper.GetProcessShortName(processName));
                }
            }

            return(null);
        }
        /// <summary>Gets the ProcessInfo for the specified process ID on the specified machine.</summary>
        /// <param name="processId">The process ID.</param>
        /// <param name="machineName">The machine name.</param>
        /// <returns>The ProcessInfo for the process if it could be found; otherwise, null.</returns>
        public static ProcessInfo GetProcessInfo(int processId, string machineName)
        {
            if (IsRemoteMachine(machineName))
            {
                // remote case: we take the hit of looping through all results
                ProcessInfo[] processInfos = NtProcessManager.GetProcessInfos(machineName, isRemoteMachine: true);
                foreach (ProcessInfo processInfo in processInfos)
                {
                    if (processInfo.ProcessId == processId)
                    {
                        return(processInfo);
                    }
                }
            }
            else
            {
                // local case: do not use performance counter and also attempt to get the matching (by pid) process only
                ProcessInfo[] processInfos = NtProcessInfoHelper.GetProcessInfos(pid => pid == processId);
                if (processInfos.Length == 1)
                {
                    return(processInfos[0]);
                }
            }

            return(null);
        }
예제 #3
0
        /// <summary>Gets process infos for each process on the specified machine.</summary>
        /// <param name="processNameFilter">Optional process name to use as an inclusion filter.</param>
        /// <param name="machineName">The target machine.</param>
        /// <returns>An array of process infos, one per found process.</returns>
        public static ProcessInfo[] GetProcessInfos(string?processNameFilter, string machineName)
        {
            if (!IsRemoteMachine(machineName))
            {
                return(NtProcessInfoHelper.GetProcessInfos(processNameFilter: processNameFilter));
            }

            ProcessInfo[] processInfos = NtProcessManager.GetProcessInfos(machineName, isRemoteMachine: true);
            if (string.IsNullOrEmpty(processNameFilter))
            {
                return(processInfos);
            }

            ArrayBuilder <ProcessInfo> results = default;

            foreach (ProcessInfo pi in processInfos)
            {
                if (string.Equals(processNameFilter, pi.ProcessName, StringComparison.OrdinalIgnoreCase))
                {
                    results.Add(pi);
                }
            }

            return(results.ToArray());
        }
예제 #4
0
        public static ProcessInfo[] GetProcessInfos(string machineName)
        {
            bool isRemoteMachine = IsRemoteMachine(machineName);

            // Do not use performance counter for local machine
            if (!isRemoteMachine)
            {
                return(NtProcessInfoHelper.GetProcessInfos());
            }
            return(NtProcessManager.GetProcessInfos(machineName, isRemoteMachine));
        }
        public static ProcessInfo[] GetProcessInfos(string machineName)
        {
            bool isRemoteMachine = IsRemoteMachine(machineName);

            if (IsNt)
            {
                if (!isRemoteMachine && (Environment.OSVersion.Version.Major >= 5))
                {
                    return(NtProcessInfoHelper.GetProcessInfos());
                }
                return(NtProcessManager.GetProcessInfos(machineName, isRemoteMachine));
            }
            if (isRemoteMachine)
            {
                throw new PlatformNotSupportedException(SR.GetString("WinNTRequiredForRemote"));
            }
            return(WinProcessManager.GetProcessInfos());
        }
 /// <summary>Gets process infos for each process on the specified machine.</summary>
 /// <param name="machineName">The target machine.</param>
 /// <returns>An array of process infos, one per found process.</returns>
 public static ProcessInfo[] GetProcessInfos(string machineName)
 {
     return(IsRemoteMachine(machineName) ?
            NtProcessManager.GetProcessInfos(machineName, isRemoteMachine: true) :
            NtProcessInfoHelper.GetProcessInfos());
 }
예제 #7
0
 /// <summary>Gets process infos for each process on the specified machine.</summary>
 /// <param name="machineName">The target machine.</param>
 /// <returns>An array of process infos, one per found process.</returns>
 public static ProcessInfo[] GetProcessInfos(string machineName)
 {
     return(IsRemoteMachine(machineName) ?
            NtProcessManager.GetProcessInfos(machineName, true) :
            NtProcessInfoHelper.GetProcessInfos()); // Do not use performance counter for local machine
 }