windows-system-icon
Extract the associated file icons with Node.js using Powershell on Windows.
Requirements
- Powershell
Usage
NPM
npm install windows-system-icon
TypeScript
;;; // this parameter is optionalgenerateIconsicons, followShortcuts.thenconsole.log"Done!".catchconsole.logerr;
JavaScript
;const icons =inputFilePath: "C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\Google Chrome.lnk"outputFilePath: "C:\\Users\\Oliver\\Desktop\\Google Chrome Icon.png"outputFormat: "Png";const followShortcuts = false; // this parameter is optional;
Supported output formats
Gif
Icon
Jpeg
Png
Tiff
Make sure to capitalize the output formats
How it works
windows-system-icon
uses Powershell in the background to extract the associated file icons.
Here is the powershell script that gets executed in the background:
Add-Type -AssemblyName System.Drawing$filePath = "<input-file-path>";$fileExists = Test-Path -Path $filePath;if ($fileExists -and $filePath.EndsWith(".lnk")) {Try {$sh = New-Object -ComObject WScript.Shell;$filePath = $sh.CreateShortcut($filePath).TargetPath;}Catch {<# do nothing #>}}if ($fileExists) {$icon = [System.Drawing.Icon]::ExtractAssociatedIcon("<input-file-path>");$bitmap = $icon.ToBitmap().save("<output-file-path>", [System.Drawing.Imaging.ImageFormat]::<output-format>);}