Ejemplo n.º 1
0
 /// <summary>
 /// Fetches the icon associated with the provided process.
 /// </summary>
 /// <param name="process">The process to check.</param>
 /// <returns>An Icon associated with the given process. Returns null if there is no icon.</returns>
 public static Icon GetIcon(this Process process)
 {
     return(WindowsProcessInfo.GetIcon(process));
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Determines if the provided process is a system process.
 /// </summary>
 /// <param name="process">The process to check.</param>
 /// <returns>A value indicating whether or not the given process is a system process.</returns>
 public static Boolean IsSystemProcess(this Process process)
 {
     return(WindowsProcessInfo.IsProcessSystemProcess(process));
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Determines if a process has a window.
 /// </summary>
 /// <param name="process">The process to check.</param>
 /// <returns>A value indicating whether or not the given process has a window.</returns>
 public static Boolean HasWindow(this Process process)
 {
     return(WindowsProcessInfo.IsProcessWindowed(process));
 }
Ejemplo n.º 4
0
            internal static List <WindowsProcessInfo> GetPlatformProcesses(string serverName)
            {
                var machineName = serverName;

                if (string.IsNullOrWhiteSpace(machineName))
                {
                    machineName = Environment.MachineName;
                }

                var result = new List <WindowsProcessInfo>();

                using (var serverHandle = Interop.Windows.WTSOpenServerW(machineName))
                {
                    if (serverHandle == null || serverHandle.IsInvalid)
                    {
                        return(result);
                    }

                    try
                    {
                        var processInfoPtr = IntPtr.Zero;
                        var processCount   = 0U;
                        var success        = Interop.Windows.WTSEnumerateProcessesW(
                            serverHandle,
                            0,
                            1,
                            ref processInfoPtr,
                            ref processCount
                            );
                        var dataSize = Marshal.SizeOf(typeof(Interop.Windows.WindowsTerminalServiceProcessInfo));
                        var currentProcessInfoPtr = processInfoPtr;

                        if (success)
                        {
                            for (var processIndex = 0; processIndex < processCount; processIndex++)
                            {
                                var processInfo = (Interop.Windows.WindowsTerminalServiceProcessInfo)Marshal.PtrToStructure(
                                    currentProcessInfoPtr,
                                    typeof(Interop.Windows.WindowsTerminalServiceProcessInfo)
                                    );
                                currentProcessInfoPtr += dataSize;

                                var userSid = string.Empty;
                                success = Interop.Windows.ConvertSidToStringSidW(processInfo.pUserSid, ref userSid);
                                if (!success)
                                {
                                    userSid = string.Empty;
                                }

                                var windowsProcessInfo = new WindowsProcessInfo
                                {
                                    Id        = (int)processInfo.processId,
                                    Name      = processInfo.pProcessName,
                                    SessionId = (int)processInfo.sessionId,
                                    UserSid   = userSid
                                };
                                result.Add(windowsProcessInfo);
                            }
                            Interop.Windows.WTSFreeMemory(processInfoPtr);
                        }
                    }
                    catch (Exception e)
                    {
                        Logger.GetInstance(typeof(Windows)).Error("Can not get Windows process list: " + e.Message);
                    }

                    return(result);
                }
            }