Ejemplo n.º 1
0
        public ProcessWatcher(string ConfigPath)
        {
            this.ConfigPath = ConfigPath;

            this.firstLevelProcessHashes  = new IndexedList();
            this.secondLevelProcessHashes = ConfigLoader.LoadSecondHashConfig(ConfigPath);
            this.processExeNames          = new Dictionary <string, App>();

            StartWatch = new ManagementEventWatcher(new WqlEventQuery("SELECT * FROM Win32_ProcessStartTrace"));
            StartWatch.EventArrived += new EventArrivedEventHandler(startWatch_ProcessCreated);
            StartWatch.Start();
        }
Ejemplo n.º 2
0
 public static IndexedList LoadSecondHashConfig(string path)
 {
     if (!Directory.Exists(path))
     {
         Directory.CreateDirectory(path);
     }
     if (!File.Exists($"{path}\\second.json"))
     {
         IndexedList create = new IndexedList();
         SaveSecondHashConfig(path, create);
         return(create);
     }
     return(JsonConvert.DeserializeObject <IndexedList>(File.ReadAllText($"{path}\\second.json")));
 }
Ejemplo n.º 3
0
        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);
            }
        }
Ejemplo n.º 4
0
 public static void SaveSecondHashConfig(string path, IndexedList config)
 {
     File.WriteAllText($"{path}\\second.json", JsonConvert.SerializeObject(config));
 }