public static void Main(string[] args) { bool exportBase64 = true; AppDomain.CurrentDomain.AssemblyResolve += OnResolveAssembly; //App.Main(); //global::App.Main(); //LS4W.App.Main(); List <WindowsProgram> installedPrograms = new List <WindowsProgram>(); string registryKey_AppPaths = @"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths"; //Get executables using (RegistryKey key = Registry.LocalMachine.OpenSubKey(registryKey_AppPaths)) { foreach (string subkeyName in key.GetSubKeyNames()) { using (RegistryKey subkey = key.OpenSubKey(subkeyName)) { object rawLocation = subkey.GetValue(""); object rawPath = subkey.GetValue("Path"); if (rawLocation is null) { continue; } if (rawPath is null) { continue; } WindowsProgram app = new WindowsProgram(); app.executableLocation = rawLocation.ToString(); app.installLocation = rawPath.ToString(); app.iconPaths = new List <string>(); if (!File.Exists(app.executableLocation)) { continue; } string assemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string iconPath = assemblyPath + @"\icons\"; if (!Directory.Exists(iconPath)) { Directory.CreateDirectory(iconPath); } IconExtractor ie = new IconExtractor(app.executableLocation); if (ie.Count == 0) //contains no icons { continue; } List <Icon> iconVariations = IconUtil.Split(ie.GetIcon(0)).ToList(); foreach (var(icon, index) in iconVariations.WithIndex()) { string iconExportName = Path.GetFileName(app.executableLocation) + "_" + index + ".png"; Bitmap iconAsBitmap = icon.ToBitmap(); iconAsBitmap.Save(iconPath + iconExportName, ImageFormat.Png); app.iconPaths.Add(iconPath + iconExportName); } if (exportBase64) { Icon largestIcon = iconVariations.OrderByDescending(icon => icon.Width).First(); Bitmap iconAsBitmap = largestIcon.ToBitmap(); using (MemoryStream ms = new MemoryStream()) { iconAsBitmap.Save(ms, ImageFormat.Png); byte[] iconAsBytes = ms.ToArray(); app.iconB64 = Convert.ToBase64String(iconAsBytes); } } installedPrograms.Add(app); } } } string jsonString = JsonSerializer.Serialize(installedPrograms); Console.WriteLine(jsonString); }
static void Main(string[] args) { List <WindowsProgram> installedPrograms = new List <WindowsProgram>(); string registryKey_AppPaths = @"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths"; //Get executables using (RegistryKey key = Registry.LocalMachine.OpenSubKey(registryKey_AppPaths)) { foreach (string subkeyName in key.GetSubKeyNames()) { using (RegistryKey subkey = key.OpenSubKey(subkeyName)) { object rawLocation = subkey.GetValue(""); object rawPath = subkey.GetValue("Path"); if (rawLocation is null) { continue; } if (rawPath is null) { continue; } WindowsProgram app = new WindowsProgram(); app.executableLocation = rawLocation.ToString(); app.installLocation = rawPath.ToString(); installedPrograms.Add(app); } } } foreach (WindowsProgram app in installedPrograms) { if (!File.Exists(app.executableLocation)) { continue; } var versionInfo = FileVersionInfo.GetVersionInfo(app.executableLocation); app.applicationName = versionInfo.FileDescription; app.publisherName = versionInfo.CompanyName; app.iconPaths = new List <string>(); IconExtractor ie = new IconExtractor(app.executableLocation); if (ie.Count == 0) { continue; } Icon icon = ie.GetIcon(0); Icon[] iconVariations = IconUtil.Split(icon); string assemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string iconPath = assemblyPath + @"\icons\"; if (!Directory.Exists(iconPath)) { Directory.CreateDirectory(iconPath); } for (int a = 0; a < iconVariations.Count(); a++) { string iconExportName = Path.GetFileName(app.executableLocation) + "_" + a + ".png"; Bitmap iconAsBitmap = iconVariations[a].ToBitmap(); iconAsBitmap.Save(iconPath + iconExportName, ImageFormat.Png); app.iconPaths.Add(iconPath + iconExportName); } } string jsonString = JsonSerializer.Serialize(installedPrograms); Console.WriteLine(jsonString); }