Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extract icon using powershell - resulting file is not windows icon file

I have this simple script - which seems to be how every search I find tells me to extract an icon for use:

$Format = [System.Drawing.Imaging.ImageFormat]::Icon

$Source = 'C:\Windows\System32\DeviceProperties.exe'
[System.Drawing.Icon]::ExtractAssociatedIcon($Source).ToBitmap().Save("c:\temp\extracted.ico",$Format)

Problem being that the resulting file is not a Windows icon file. As evidenced when you try to apply this icon to a shortcut or similar I receive this Windows error:

The file C:\Temp\extracted contains no icons

Choose an icon from the list or specify a diferent file

I'm assuming here it's because the result is a bitmap rather than an icon format.

The question is - how to convert this to a proper icon file ready for use?

like image 948
Scepticalist Avatar asked Oct 20 '25 18:10

Scepticalist


1 Answers

The exported file: c:\temp\extracted.ico is a png file, not a ico file. I haven't found a way to convert this with powershell to ico format, either. But gimp e.g. can do this job.

Do the following:

  1. Open that file in gimp with (File / Open...)
  2. Click on Export as...
  3. Change file extension from .png to .ico (if necessary)
  4. Click on Export button
  5. Export Icon as Windows Icon window appears, click on Export button (or adjust settings, if necessary)

This will convert the file format from png to ico and you won't lose transparency.

like image 124
Adelphos Avatar answered Oct 23 '25 07:10

Adelphos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!