1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| $code = @"
using System;
using System.Drawing;
using System.Runtime.InteropServices;
namespace System
{
public class IconExtractor
{
public static Icon Extract(string file, int number, bool largeIcon)
{
IntPtr large;
IntPtr small;
ExtractIconEx(file, number, out large, out small, 1);
try
{
return Icon.FromHandle(largeIcon ? large : small);
}
catch
{
return null;
}
}
[DllImport("Shell32.dll", EntryPoint = "ExtractIconExW", CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
private static extern int ExtractIconEx(string sFile, int iIndex, out IntPtr piLargeVersion, out IntPtr piSmallVersion, int amountIcons);
}
}
"@
Add-Type -TypeDefinition $code -ReferencedAssemblies System.Drawing
Add-Type -AssemblyName System.Windows.Forms
$Icon = [System.IconExtractor]::Extract("C:\Windows\System32\shell32.dll", 27, $true)
$PictureBox1 = New-Object system.Windows.Forms.PictureBox
$PictureBox1.width = 60
$PictureBox1.height = 30
$PictureBox1.location = New-Object System.Drawing.Point(71,81)
$PictureBox1.Image = $Icon
$PictureBox1.SizeMode = [System.Windows.Forms.PictureBoxSizeMode]::zoom
$form = New-Object System.Windows.Forms.Form
$form.Size = New-Object System.Drawing.Size(300,200)
$form.StartPosition = 'CenterScreen'
$form.controls.AddRange(@($PictureBox1))
$form.ShowDialog() |
Partager