-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.ps1
98 lines (64 loc) · 4.41 KB
/
menu.ps1
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
# Options
$jsontext = @"
[
{
"Program": "Notepad",
"EXE": "c:\\windows\\notepad.exe"
},
{
"Program": "Notepad++",
"EXE": "C:\\Program Files (x86)\\Notepad++\\Notepad++.exe"
},
{
"Program": "Notepad++ 2",
"EXE": "C:\\Program Files (x86)\\Notepad++\\Notepad++.exe"
},
{
"Program": "Write",
"EXE": "c:\\windows\\write.exe"
},
{
"Program": "Internet Explorer",
"EXE": "C:\\Program Files\\Internet Explorer\\iexplore.exe"
},
{
"Program": "Chrome",
"EXE": "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"
}
]
"@
# --------------------
# Do not edit anything below this.
# --------------------
$list = $jsontext | convertfrom-json
$button_y = 25
$button_kerning = 10
# File name from command line argument
$targetfile = $args[0]
if (!$targetfile) {write-host "Missing argument. The program does not know which file to open. Use the command line to specify the file (menu.exe file.txt) or drag a file over menu.exe" -foregroundcolor red; exit}
#if (![System.IO.File]::Exists($targetfile)) {write-host "File does not exist" -foregroundcolor red; exit}
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$MyForm = New-Object System.Windows.Forms.Form
$MyForm.Text="Open with"
$ysize = 50 + ($list.length * ($button_y + $button_kerning))
$MyForm.Size = New-Object System.Drawing.Size(320,$ysize)
$mbutton=@(New-Object System.Windows.Forms.Button)
$y=10 # Position of button kerning from top
foreach ($program in $list) {
$mButton = [System.Windows.Forms.Button]@{
Text=$program.program;
Top=$y.ToString(); #position of button
Left="25";
Anchor="Left,Top";
Size = New-Object System.Drawing.Size(250,$button_y);
}
$mButton.Add_Click({
#iex $($program.exe) $targetfile
iex "&`"$($program.exe)`" `"$targetfile`""
$MyForm.close()
}.GetNewClosure())
$MyForm.Controls.Add($mButton)
$y += $button_y + $button_kerning # position of button incriment
}
$MyForm.ShowDialog() | Out-Null