WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: stanl on September 19, 2020, 07:08:41 AM

Title: CLR - Extract Icon
Post by: stanl on September 19, 2020, 07:08:41 AM
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
Title: Re: CLR - Extract Icon
Post by: td on September 19, 2020, 08:27:46 AM
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 )
Title: Re: CLR - Extract Icon
Post by: stanl on September 19, 2020, 09:39:33 AM
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.



Title: Re: CLR - Extract Icon
Post by: stanl on September 20, 2020, 06:10:20 AM
You could eliminate the stream object with


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


but that really saves as .png -
Title: Re: CLR - Extract Icon
Post by: kdmoyers on September 21, 2020, 12:26:36 PM
Thanks everyone.

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

-Kirby