From 8e3c10edf582deefbc1438f4682231da334115a1 Mon Sep 17 00:00:00 2001 From: Fmstrat Date: Wed, 18 Nov 2020 17:02:07 -0500 Subject: [PATCH] Updated powershell script for icons and names --- install/ExtractPrograms.ps1 | 163 +++--------------------------------- 1 file changed, 11 insertions(+), 152 deletions(-) diff --git a/install/ExtractPrograms.ps1 b/install/ExtractPrograms.ps1 index e27986b..b8a765a 100644 --- a/install/ExtractPrograms.ps1 +++ b/install/ExtractPrograms.ps1 @@ -1,4 +1,4 @@ -# powershell.exe -ExecutionPolicy Bypass -File \\tsclient\home\Documents\Repos\winapps\install\ExtractPrograms.ps1 +# powershell.exe -ExecutionPolicy Bypass -File \\tsclient\home\Documents\Repos\winapps\install\ExtractPrograms.ps1 > \\tsclient\home\.local\share\winapps\include Function Get-Icon { <# @@ -205,160 +205,19 @@ Function Get-Icon { } } -Function Export-Icon { -<# - .SYNOPSIS - Export-Icon exports high-quality icons stored within .DLL and .EXE files. - - .DESCRIPTION - Export-Icon can export to a number of formats, including ico, bmp, png, jpg, gif, emf, exif, icon, tiff, and wmf. In addition, it can also export to a different size. - - This function quickly exports *all* icons stored within the resource file. - - .PARAMETER Path - Path to the .dll or .exe - - .PARAMETER Directory - Directory where the exports should be stored. If no directory is specified, all icons will be exported to the TEMP directory. - - .PARAMETER Size - This specifies the pixel size of the exported icons. All icons will be squares, so if you want a 16x16 export, it would be -Size 16. - - Valid sizes are 8, 16, 24, 32, 48, 64, 96, and 128. The default is 32. - - .PARAMETER Type - This is the type of file you would like to export to. The default is .ico - - Valid types are ico, bmp, png, jpg, gif, emf, exif, icon, tiff, and wmf. The default is ico. - - .NOTES - Author: Chrissy LeMaire - Requires: PowerShell 3.0 - Version: 2.0 - DateUpdated: 2016-June-6 - - .LINK - https://gallery.technet.microsoft.com/scriptcenter/Export-Icon-from-DLL-and-9d309047 - - .EXAMPLE - Export-Icon C:\windows\system32\imageres.dll - - Exports all icons stored witin C:\windows\system32\imageres.dll to $env:temp\icons. Creates directory if required and automatically opens output directory. - - .EXAMPLE - Export-Icon -Path "C:\Program Files (x86)\VMware\Infrastructure\Virtual Infrastructure Client\Launcher\VpxClient.exe" -Size 64 -Type png -Directory C:\temp - - Exports the high-quality icon within VpxClient.exe to a transparent png in C:\temp\. Resizes the exported image to 64x64. Creates directory if required - and automatically opens output directory. - - - #> - - [CmdletBinding()] - Param( - [Parameter(Mandatory=$true)] - [string]$Path, - [string]$Directory, - [ValidateSet(8,16,24,32,48,64,96,128)] - [int]$Size = 32, - [ValidateSet("ico","bmp","png","jpg","gif", "jpeg", "emf", "exif", "icon", "tiff", "wmf")] - [string]$Type = "ico" - ) - - BEGIN { - - # Thanks Thomas Levesque at http://bit.ly/1KmLgyN and darkfall http://git.io/vZxRK - $code = ' - using System; - using System.Drawing; - using System.Runtime.InteropServices; - using System.IO; - - namespace System { - public class IconExtractor { - public static Icon Extract(string file, int number, bool largeIcon) { - IntPtr large; - IntPtr small; - ExtractIconEx(file, number, out large, out small, 1); - try { return Icon.FromHandle(largeIcon ? large : small); } - catch { return null; } - } - [DllImport("Shell32.dll", EntryPoint = "ExtractIconExW", CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)] - private static extern int ExtractIconEx(string sFile, int iIndex, out IntPtr piLargeVersion, out IntPtr piSmallVersion, int amountIcons); - } - } - - public class PngIconConverter - { - public static bool Convert(System.IO.Stream input_stream, System.IO.Stream output_stream, int size, bool keep_aspect_ratio = false) - { - System.Drawing.Bitmap input_bit = (System.Drawing.Bitmap)System.Drawing.Bitmap.FromStream(input_stream); - if (input_bit != null) - { - int width, height; - if (keep_aspect_ratio) - { - width = size; - height = input_bit.Height / input_bit.Width * size; - } - else - { - width = height = size; - } - System.Drawing.Bitmap new_bit = new System.Drawing.Bitmap(input_bit, new System.Drawing.Size(width, height)); - if (new_bit != null) - { - System.IO.MemoryStream mem_data = new System.IO.MemoryStream(); - new_bit.Save(mem_data, System.Drawing.Imaging.ImageFormat.Png); - - System.IO.BinaryWriter icon_writer = new System.IO.BinaryWriter(output_stream); - if (output_stream != null && icon_writer != null) - { - icon_writer.Write((byte)0); - icon_writer.Write((byte)0); - icon_writer.Write((short)1); - icon_writer.Write((short)1); - icon_writer.Write((byte)width); - icon_writer.Write((byte)height); - icon_writer.Write((byte)0); - icon_writer.Write((byte)0); - icon_writer.Write((short)0); - icon_writer.Write((short)32); - icon_writer.Write((int)mem_data.Length); - icon_writer.Write((int)(6 + 16)); - icon_writer.Write(mem_data.ToArray()); - icon_writer.Flush(); - return true; - } - } - return false; - } - return false; - } - - public static bool Convert(string input_image, string output_icon, int size, bool keep_aspect_ratio = false) - { - System.IO.FileStream input_stream = new System.IO.FileStream(input_image, System.IO.FileMode.Open); - System.IO.FileStream output_stream = new System.IO.FileStream(output_icon, System.IO.FileMode.OpenOrCreate); - - bool result = Convert(input_stream, output_stream, size, keep_aspect_ratio); - - input_stream.Close(); - output_stream.Close(); - - return result; - } - } -' - - Add-Type -TypeDefinition $code -ReferencedAssemblies System.Drawing, System.IO -ErrorAction SilentlyContinue -} - - +"NAMES=()" +"ICONS=()" +"EXES=()" Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\*" | Select-Object -Property "(default)" -Unique | Where-Object {$_."(default)" -ne $null} | ForEach-Object { - $Icon = Get-Icon -Path $_."(default)".Trim('"') -ToBase64 + $Exe = $_."(default)".Trim('"') + $Name = (Get-Item $Exe).VersionInfo.FileDescription.Trim() -replace " "," " + $Icon = Get-Icon -Path $Exe -ToBase64 + #Get-ItemProperty $Exe -Name VersionInfo + "NAMES+=(""$Name"")" + "EXES+=(""$Exe"")" + "ICONS+=(""$Icon"")" }