This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

windows-system-icon
TypeScript icon, indicating that this package has built-in type declarations

0.0.8 • Public • Published

windows-system-icon

Extract the associated file icons with Node.js using Powershell on Windows.

Build status

Requirements

  • Powershell

Usage

NPM

npm install windows-system-icon

TypeScript

import { generateIcons, Icon } from "../dist/index";

const icons: Icon[] = [
    {
        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

generateIcons(icons, followShortcuts)
    .then(() => console.log("Done!"))
    .catch((err) => console.log(err));

JavaScript

import { generateIcons } from "../dist/index";

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

generateIcons(icons, followShortcuts)
    .then(() => console.log("Done!"))
    .catch((err) => console.log(err));

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>); 
}

Package Sidebar

Install

npm i windows-system-icon

Weekly Downloads

28

Version

0.0.8

License

MIT

Unpacked Size

36.9 kB

Total Files

16

Last publish

Collaborators

  • oliverschwendener