-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy path1006.ps1
More file actions
111 lines (92 loc) · 3.66 KB
/
Copy path1006.ps1
File metadata and controls
111 lines (92 loc) · 3.66 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<#
.Synopsis
Makes a baloon tip in the notification area
.Description
With just a few arguments, it is easy to make some text appear in a little balloon.
You can specify an icon file (*.ico) with the -icon argument, if you don't then
the first icon of the host is used.
out-balloon accepts pipeline input, strings only please.
It blocks for the duration of the balloon display, 3 seconds by default. Simple
fixes for this are welcome.
timeout should be an integer value.
INSTALLATION:
um, save this text in a file named out-balloon.ps1 in your path
.Example
out-balloon "hey, your job is done." -icon "C:\Program Files\Microsoft Office\Office12\MYSL.ICO"
"job done." | out-balloon
#>
param(
[Parameter(ValueFromPipeline=$true,Position=0,Mandatory=$true)]
[Alias('output')]
[string]$text,
[string]$icon,
[int32]$timeout = 3
)
begin
{
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
$not = new-object System.Windows.Forms.NotifyIcon
if ($icon -eq $null)
{
if ($win32extraciconex -eq $null)
{
$script:ExtractIconEx = Add-Type –memberDefinition @"
[DllImport("Shell32", CharSet=CharSet.Auto)]
private static extern int ExtractIconEx (string lpszFile, int nIconIndex,
IntPtr[] phIconLarge,IntPtr[] phIconSmall,int nIcons);
[DllImport("user32.dll", EntryPoint="DestroyIcon", SetLastError=true)]
private static extern int DestroyIcon(IntPtr hIcon);
public static System.Drawing.Icon ExtractIconFromExe(string file, bool large)
{
int readIconCount = 0;
IntPtr[] hDummy = new IntPtr[1] {IntPtr.Zero};
IntPtr[] hIconEx = new IntPtr[1] {IntPtr.Zero};
try
{
if(large)
readIconCount = ExtractIconEx(file,0, hIconEx, hDummy, 1);
else
readIconCount = ExtractIconEx(file,0, hDummy, hIconEx, 1);
if(readIconCount > 0 && hIconEx[0] != IntPtr.Zero)
{
System.Drawing.Icon extractedIcon = (System.Drawing.Icon)System.Drawing.Icon.FromHandle(hIconEx[0]).Clone();
return extractedIcon;
}
else // NO ICONS READ
return null;
}
catch(Exception ex)
{
throw new ApplicationException("Failed extracting icon", ex);
}
finally
{
foreach(IntPtr ptr in hIconEx)
if(ptr != IntPtr.Zero)
DestroyIcon(ptr);
foreach(IntPtr ptr in hDummy)
if(ptr != IntPtr.Zero)
DestroyIcon(ptr);
}
}
"@ -name “Win32ExtractIconEx” -namespace win32api –passThru -ReferencedAssemblies "System.Drawing"
}
$not.Icon = $extractIconEx::ExtractIconFromExe((get-process -Id $pid).mainmodule.filename, $true)
}
else
{
$not.Icon = new-object System.Drawing.Icon($icon)
}
$not.visible = $true
}
process
{
$not.BalloonTipText = $text
$not.ShowBalloonTip($timeout)
sleep $timeout
}
end
{
$not.dispose()
}