CLR - Extract Icon

Started by stanl, September 19, 2020, 07:08:41 AM

Previous topic - Next topic

stanl

I know WB can do this natively, but interest arose from Kirby's thread about using CLR for Snapshot. I was playing with Icon class but errors. Need help with oStream = ObjectClrNew('System.IO.FileStream',"C:\temp\WB.ico",FileMode.Create)


Code (WINBATCH) Select


path = "C:\Program Files (x86)\WinBatch\System\Winbatch.exe"


ObjectClrOption('useany', 'System')
ObjectClrOption('useany', 'System.Drawing')
ObjectClrOption('useany', 'System.IO')
oIcon =  ObjectClrNew('System.Drawing.Icon')
oStream = ObjectClrNew('System.IO.FileStream',"C:\temp\WB.ico",FileMode.Create)
cIcon = oIcon.ExtractAssociatedIcon(path)
cIcon.Save(oStream)


oIcon.Dispose()
oIcon = 0
oStream.Dispose()
oStream = 0
Exit

td

See the previous discussions regarding enumerations being a type and constructors/methods with multiple overloads.

Code (winbatch) Select
ObjectClrOption('useany', 'System.IO')

enumFileMode = ObjectClrNew('System.IO.FileMode')
FModeCreate = ObjectClrType('System.IO.FileMode', enumFileMode.Create)
oStream = ObjectClrNew('System.IO.FileStream',"C:\temp\WB.ico",FModeCreate )
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

stanl

Thanks, as usual. Did check that output [for another exe] would work as WB compiled Icon - but poor quality. I believe the format is 32x32.




stanl

You could eliminate the stream object with


oIcon.ExtractAssociatedIcon(path).ToBitmap().Save("C:\temp\WB.ico")


but that really saves as .png -

kdmoyers

Thanks everyone.

This growing library of CLR examples really helps an examples-based learner like me!

-Kirby
The mind is everything; What you think, you become.