Пример #1
0
        public void Initialize(ProcessPropertiesDto properties, ProcessViewModel process, ITargetedRestClient restClient)
        {
            _restClient = restClient;

            StaticPropertiesDto = properties;
            PropertiesDto       = properties;
            Process             = process;

            if (process.ParentProcessId != 0)
            {
                string parentProcess;
                if (process.ParentViewModel != null)
                {
                    parentProcess = process.Name;
                }
                else
                {
                    parentProcess = "<" + Tx.T("TaskManager:NotAvailable") + ">";
                }

                ParentProcessString = $"{parentProcess} ({process.ParentProcessId})";
            }

            Icon   = ImageUtilities.GetBitmapImage(properties.Icon);
            Status = properties.Status;

            InitializeChannel().Forget();
            UpdateActiveConnections().Forget();
        }
Пример #2
0
        public IActionResult GetProperties(int processId)
        {
            if (!GetProcess(processId, out var process, out var errorResult))
            {
                return(errorResult);
            }

            var dto = new ProcessPropertiesDto();

            using (process)
            {
                using (var searcher = new ManagementObjectSearcher("root\\CIMV2", $"SELECT * FROM Win32_Process WHERE ProcessId = {processId}"))
                    using (var results = searcher.Get())
                    {
                        var wmiProcess = results.Cast <ManagementObject>().SingleOrDefault();
                        if (wmiProcess == null)
                        {
                            return(NotFound());
                        }

                        dto.ApplyProperties(process, wmiProcess);

                        if (wmiProcess.TryGetProperty("ExecutablePath", out string executablePath))
                        {
                            try
                            {
                                dto.Icon = FileUtilities.GetFileIcon(executablePath, 32);
                            }
                            catch (Exception)
                            {
                                // ignored
                            }
                        }
                    }

                try
                {
                    dto.IsWow64Process = ProcessExtensions.Is64BitProcess(process.Handle);
                }
                catch (Exception)
                {
                    // ignored
                }
            }

            return(Ok(dto));
        }