private static void UpdateProcesses() { foreach (var process in Process.GetProcesses().OrderBy(x => x.ProcessName)) { //Be self aware. if (process.Id == ThisProcess.Id) { continue; } var toLower = process.ProcessName.ToLower(); if (Ignore.Contains(toLower)) { continue; } if (CachedProcesses.ContainsKey(toLower) && CachedProcesses[toLower].ContainsKey(process.Id)) { continue; } else { PProcess pp = new PProcess() { Process = process, RoutingEnabled = SerializationHandler.Configuration.Processes.Any(p => p.ProcessName.Equals(process.ProcessName)), }; if (IconGrabber.TryGetIconBitmap(process, 16, out Bitmap icon)) { pp.Icon = icon; } else { // If we fail to load the icon, we probably dont have access rights to the given process, // we wont be able to hook the socket, so from now on, we ignore this process. Ignore.Add(toLower); continue; } if (!CachedProcesses.ContainsKey(toLower)) { CachedProcesses.Add(toLower, new Dictionary <int, PProcess>()); } if (!CachedProcesses[toLower].ContainsKey(process.Id)) { CachedProcesses[toLower].Add(process.Id, pp); } } } //Notify UI the latest processes. ProcessesUpdated?.Invoke(null, null); }
protected internal override void Write() { WriteByte(4); WriteString(info.Name); WriteString(((double)(info.Length / 1024f / 1024f)).ToString("N") + " MB"); WriteString(info.Extension); WriteString(info.Attributes.ToString()); WriteString(info.FullName); WriteBytes(BitmapToBytes(IconGrabber.GetIcon(info.FullName, true))); }
protected internal override void Write() { WriteByte(1); try { WriteString(p.ProcessName); } catch { WriteString(""); } try { WriteShort((short)p.Id); } catch { WriteShort(0); } try { WriteString(p.MainWindowTitle); } catch { WriteString(""); } try { WriteShort((short)p.Threads.Count); } catch { WriteShort(0); } try { WriteString(p.Responding.ToString()); } catch { WriteString("False"); } try { WriteString(p.StartTime.ToString()); } catch { WriteString("Unknown"); } try { WriteInteger((int)p.BasePriority); } catch { WriteByte(0); } try { WriteInteger((int)p.Handle); } catch { WriteInteger(0); } try { WriteString(p.MainModule.FileName); } catch { WriteString(""); } try { byte[] imageBytes = BitmapToBytes(IconGrabber.GetIcon(p.MainModule.FileName, true)); WriteShort((short)imageBytes.Length); WriteBytes(imageBytes); } catch { WriteShort(0); } }