public StartMenuHandler(string ConfigPath, string[] StartMenuPathes) : base(ConfigPath) { IndexedList firstSaved = ConfigLoader.LoadFirstHashConfig(ConfigPath); //Scan Menu Folder foreach (string menu_path in StartMenuPathes) { foreach (string symlink_path in Directory.GetFiles(menu_path, "*.lnk", SearchOption.AllDirectories)) { string name = Path.GetFileNameWithoutExtension(symlink_path).ToLower(); var link = Symlink.GetRealPath(symlink_path); if (Path.GetExtension(link.TargetPath) != ".exe") { continue; } App output = firstSaved.TryToGetApp(name); if (output != null) { firstLevelProcessHashes.TryToAdd(name, link.TargetPath, output.lastStart, ref output, link.Arguments); } else { firstLevelProcessHashes.TryToAdd(name, link.TargetPath, ref output, link.Arguments); } if (!processExeNames.ContainsKey(link.TargetPath)) { processExeNames.Add(link.TargetPath, output); } } } //Start watching StartUp folder foreach (string menu_path in StartMenuPathes) { FileSystemWatcher watcher = new FileSystemWatcher(); watcher.Path = menu_path; watcher.IncludeSubdirectories = true; watcher.Filter = "*.lnk"; watcher.Created += new FileSystemEventHandler(OnCreated); watcher.Deleted += new FileSystemEventHandler(OnDeleted); watcher.Renamed += new RenamedEventHandler(OnRenamed); watcher.EnableRaisingEvents = true; watchers.Add(watcher); } }
private void startWatch_ProcessCreated(object sender, EventArrivedEventArgs e) { try { string fullpath = Process.GetProcessById(Convert.ToInt32(e.NewEvent.Properties["ProcessID"].Value)).MainModule.FileName; if (fullpath.ToLower().StartsWith("c:\\windows\\")) { return; } string productName = FileVersionInfo.GetVersionInfo(fullpath).ProductName; int startTime = Environment.TickCount; productName = productName == null?Path.GetFileNameWithoutExtension(fullpath).ToLower() : productName.ToLower(); if (this.processExeNames.TryGetValue(fullpath, out App app) || (app = firstLevelProcessHashes.TryToGetApp(productName)) != null) { Logger.log.Info($"Update time: {fullpath}, {productName}"); app.lastStart = DateTime.Now; } else { Logger.log.Info($"Added to secondLevelHash: {fullpath}, {productName}"); this.secondLevelProcessHashes.TryToAdd(productName, fullpath, ref app); this.processExeNames.Add(fullpath, app); } Console.WriteLine($"Process created time: {Environment.TickCount - startTime}"); } catch { } //If process ended earlier }