private void SearchInStartMenu(string pathStartup, RegistryKey startupApprovedKey) { //Thread.Sleep(1000); SearchInDirectory?.Invoke(pathStartup); string[] paths; try { paths = Directory.GetFiles(pathStartup).Where(f => !f.ToLower().EndsWith(".ini")).ToArray(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); return; } IWshShell wsh = new WshShell(); foreach (var item in paths) { StartupFile file = new StartupFile(); PathParse PathInfo = new PathParse(item); if (item.EndsWith("lnk")) { var lnk = (IWshShortcut)wsh.CreateShortcut(item); var lnkInfo = new PathParse(lnk.TargetPath); file.FileName = lnkInfo.Name; file.Params = lnk.Arguments; file.FilePath = lnkInfo.Path; } else { file.FileName = PathInfo.Name; file.Params = PathInfo.Params; file.FilePath = PathInfo.Path; } file.Name = PathInfo.Name; file.Path = pathStartup; file.Icon = GetIcon(file.FilePath + file.FileName); file.ApprovedKeyPath = startupApprovedKey; if (startupApprovedKey != null) { file.Enabled = GetEnabled(file.Name, startupApprovedKey); } SearchedFile?.Invoke(file); ResultCount++; } }
private void SearchInRegistry(RegistryKey key, RegistryKey baseKey) { //Thread.Sleep(1000); SearchInDirectory?.Invoke(key.Name); RegistryKey startupApprovedKey; try { if (key.Name.Contains("Wow6432Node")) { startupApprovedKey = baseKey.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\StartupApproved\Run32", true); } else { startupApprovedKey = baseKey.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\StartupApproved\Run", true); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); //return; startupApprovedKey = null; } foreach (var item in key.GetValueNames()) { if (item == "") { continue; } StartupFile file = new StartupFile(); PathParse PathInfo = new PathParse(key.GetValue(item).ToString()); file.Name = item; file.FileName = PathInfo.Name; file.FilePath = PathInfo.Path; file.Params = PathInfo.Params; file.Path = key.Name; file.Icon = GetIcon(file.FilePath + file.FileName); file.ApprovedKeyPath = startupApprovedKey; if (startupApprovedKey != null) { file.Enabled = GetEnabled(item, startupApprovedKey); } SearchedFile?.Invoke(file); ResultCount++; } // FilesParse(paths, names, key.Name); }
private void SearchedFile(StartupFile _file) { Dispatcher.Invoke(() => startupFiles.Add(_file)); }