Repository navigation
Expand file tree
/
Copy pathAppExecutionAliasManager_GUI.ps1
More file actions
407 lines (346 loc) · 17.4 KB
/
Copy pathAppExecutionAliasManager_GUI.ps1
File metadata and controls
407 lines (346 loc) · 17.4 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
<#
.SYNOPSIS
App Execution Alias Manager - A GUI tool for managing Windows application execution aliases.
.DESCRIPTION
This PowerShell script provides a graphical user interface for viewing, managing, and creating
Windows application execution aliases. It displays both Windows Store App Execution Aliases
(from WindowsApps folder) and custom registry-based App Paths aliases in a three-column format
showing alias names, full paths, and file sizes.
The application automatically loads alias information on startup and provides functionality to:
- List all registered app execution aliases
- Remove custom registry aliases (Windows Store aliases require app uninstallation)
- Create new custom aliases via registry App Paths
- Display file sizes with automatic KB/MB formatting
- Maintain window size and position across sessions
.PARAMETER None
This script does not accept any parameters.
.EXAMPLE
.\AppExecutionAliasManager_GUI.ps1
Launches the App Execution Alias Manager GUI application.
.EXAMPLE
Get-Help .\AppExecutionAliasManager_GUI.ps1 -Full
Displays complete help information for this script.
.NOTES
File Name : AppExecutionAliasManager_GUI.ps1
Author : Tony Walsh - Generated with Augment AI and VSCode
Copyright : © 2025 Tony Walsh. All rights reserved.
License : GPL-3.0
Prerequisite : PowerShell 5.1 or later, Windows Forms
Window Settings: Automatically saved to %LOCALAPPDATA%\AppExecutionAliasManager\config.json
Alias Types Supported:
- Windows Store App Execution Aliases (read-only, located in WindowsApps)
- Registry App Paths aliases (can be created/removed)
File Size Display:
- Files ≤999KB: Displayed as whole numbers in KB (rounded up)
- Files >999KB: Displayed in MB with 1 decimal place (rounded up to nearest tenth)
.LINK
https://docs.microsoft.com/en-us/windows/win32/shell/app-registration
.LINK
https://docs.microsoft.com/en-us/windows/uwp/launch-resume/launch-default-app
.FUNCTIONALITY
GUI, Alias Management, Registry Management, File System
#>
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', 'foundAliases')]
param()
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
Add-Type -AssemblyName Microsoft.VisualBasic
# Script-level variables
$script:listView = $null
$script:btnListAliases = $null
# Functions for saving/loading window settings
function Save-WindowSettings {
param($Form)
$configPath = "$env:LOCALAPPDATA\AppExecutionAliasManager\config.json"
$configDir = Split-Path $configPath -Parent
# Create directory if it doesn't exist
if (-not (Test-Path $configDir)) {
New-Item -Path $configDir -ItemType Directory -Force | Out-Null
}
$settings = @{
WindowX = $Form.Location.X
WindowY = $Form.Location.Y
WindowWidth = $Form.Size.Width
WindowHeight = $Form.Size.Height
WindowState = $Form.WindowState.ToString()
}
$settings | ConvertTo-Json | Set-Content -Path $configPath
}
function Get-WindowSettings {
param($Form)
$configPath = "$env:LOCALAPPDATA\AppExecutionAliasManager\config.json"
if (Test-Path $configPath) {
try {
$settings = Get-Content -Path $configPath | ConvertFrom-Json
if ($settings.WindowX -and $settings.WindowY) {
$Form.Location = New-Object System.Drawing.Point($settings.WindowX, $settings.WindowY)
}
if ($settings.WindowWidth -and $settings.WindowHeight) {
$Form.Size = New-Object System.Drawing.Size($settings.WindowWidth, $settings.WindowHeight)
}
if ($settings.WindowState) {
$Form.WindowState = [System.Windows.Forms.FormWindowState]::($settings.WindowState)
}
} catch {
# If any error loading settings, use defaults (current settings remain)
}
}
}
function New-Form {
$form = New-Object System.Windows.Forms.Form
$form.Text = "App Execution Alias Manager"
$form.Size = New-Object System.Drawing.Size(1024, 768)
$form.MinimumSize = New-Object System.Drawing.Size(500, 400)
$form.StartPosition = "CenterScreen"
# Load saved window settings
Get-WindowSettings -Form $form
$script:listView = New-Object System.Windows.Forms.ListView
$script:listView.Location = New-Object System.Drawing.Point(20, 10)
$script:listView.Size = New-Object System.Drawing.Size(984, 680)
$script:listView.Anchor = "Top,Left,Right,Bottom"
$script:listView.View = "Details"
$script:listView.FullRowSelect = $true
$script:listView.GridLines = $true
# Add columns with specified widths (20%, 70%, 9% = 99% total)
$null = $script:listView.Columns.Add("=== Alias Name ===", 197) # 20% of 984
$null = $script:listView.Columns.Add("=== Full Path ===", 689) # 70% of 984
$sizeColumn = $script:listView.Columns.Add("=== Size ===", 89) # 9% of 984
$sizeColumn.TextAlign = "Right"
$form.Controls.Add($script:listView)
$buttonPanel = New-Object System.Windows.Forms.FlowLayoutPanel
$buttonPanel.Dock = "Bottom"
$buttonPanel.FlowDirection = "LeftToRight"
$buttonPanel.AutoSize = $true
$buttonPanel.AutoSizeMode = "GrowAndShrink"
$buttonPanel.Padding = New-Object System.Windows.Forms.Padding(5, 3, 5, 3)
$buttonPanel.Margin = New-Object System.Windows.Forms.Padding(0)
$form.Controls.Add($buttonPanel)
$script:btnListAliases = New-Object System.Windows.Forms.Button
$script:btnListAliases.Text = "List Aliases"
$script:btnListAliases.Size = New-Object System.Drawing.Size(120, 30)
$script:btnListAliases.AutoSize = $false
$script:btnListAliases.Margin = New-Object System.Windows.Forms.Padding(3, 3, 3, 3)
$script:btnListAliases.Add_Click({
$script:listView.Items.Clear()
# Check WindowsApps folder for App Execution Aliases
$windowsAppsPath = "$env:LOCALAPPDATA\Microsoft\WindowsApps"
$foundAliases = $false
if (Test-Path $windowsAppsPath) {
# Add header row
$headerItem = New-Object System.Windows.Forms.ListViewItem("=== WindowsApps Aliases ===")
$headerItem.SubItems.Add("")
$headerItem.SubItems.Add("")
$headerItem.ForeColor = [System.Drawing.Color]::Blue
$headerItem.Font = New-Object System.Drawing.Font($script:listView.Font, [System.Drawing.FontStyle]::Bold)
$script:listView.Items.Add($headerItem)
Get-ChildItem "$windowsAppsPath\*.exe" -ErrorAction SilentlyContinue | ForEach-Object {
$aliasName = $_.Name
$target = $_.Target
if ($target) {
$item = New-Object System.Windows.Forms.ListViewItem($aliasName)
$item.SubItems.Add($target)
$item.SubItems.Add("")
} else {
# For App Execution Aliases, show file path and size
$fullPath = $_.FullName
$sizeKB = [math]::Ceiling($_.Length / 1KB)
if ($sizeKB -gt 999) {
$sizeMB = [math]::Ceiling(($_.Length / 1MB) * 10) / 10
$sizeText = "${sizeMB}MB"
} else {
$sizeText = "${sizeKB}KB"
}
$item = New-Object System.Windows.Forms.ListViewItem($aliasName)
$item.SubItems.Add($fullPath)
$item.SubItems.Add($sizeText)
}
$script:listView.Items.Add($item)
$foundAliases = $true
}
}
# Check App Paths registry
$appPathsRoot = "HKCU:\Software\Microsoft\Windows\CurrentVersion\App Paths"
if (Test-Path $appPathsRoot) {
# Add empty row and header
$emptyItem = New-Object System.Windows.Forms.ListViewItem("")
$emptyItem.SubItems.Add("")
$emptyItem.SubItems.Add("")
$script:listView.Items.Add($emptyItem)
$headerItem = New-Object System.Windows.Forms.ListViewItem("=== Registry App Paths ===")
$headerItem.SubItems.Add("")
$headerItem.SubItems.Add("")
$headerItem.ForeColor = [System.Drawing.Color]::Blue
$headerItem.Font = New-Object System.Drawing.Font($script:listView.Font, [System.Drawing.FontStyle]::Bold)
$script:listView.Items.Add($headerItem)
Get-ChildItem $appPathsRoot -ErrorAction SilentlyContinue | ForEach-Object {
$alias = $_.PSChildName
try {
$props = Get-ItemProperty $_.PSPath -ErrorAction SilentlyContinue
$defaultValue = $props.'(default)'
$sizeText = ""
if ($defaultValue) {
# Check if target file exists and get size info
if (Test-Path $defaultValue -ErrorAction SilentlyContinue) {
$fileInfo = Get-Item $defaultValue -ErrorAction SilentlyContinue
if ($fileInfo) {
$sizeKB = [math]::Ceiling($fileInfo.Length / 1KB)
if ($sizeKB -gt 999) {
$sizeMB = [math]::Ceiling(($fileInfo.Length / 1MB) * 10) / 10
$sizeText = "${sizeMB}MB"
} else {
$sizeText = "${sizeKB}KB"
}
}
} else {
# Only show "Target not found" if it looks like a file path or executable
if ($defaultValue -match '^[A-Za-z]:\\' -or $defaultValue.Contains('\') -or $defaultValue -match '\.[a-zA-Z]{2,4}$') {
$sizeText = "[Not found]"
}
}
$item = New-Object System.Windows.Forms.ListViewItem($alias)
$item.SubItems.Add($defaultValue)
$item.SubItems.Add($sizeText)
} else {
$item = New-Object System.Windows.Forms.ListViewItem($alias)
$item.SubItems.Add("[No target specified]")
$item.SubItems.Add("")
}
$script:listView.Items.Add($item)
$foundAliases = $true
} catch {
$item = New-Object System.Windows.Forms.ListViewItem($alias)
$item.SubItems.Add("[Error reading registry]")
$item.SubItems.Add("")
$script:listView.Items.Add($item)
}
}
}
if (-not $foundAliases) {
$item = New-Object System.Windows.Forms.ListViewItem("No aliases found.")
$item.SubItems.Add("")
$item.SubItems.Add("")
$script:listView.Items.Add($item)
}
})
$buttonPanel.Controls.Add($script:btnListAliases)
$btnRemoveAlias = New-Object System.Windows.Forms.Button
$btnRemoveAlias.Text = "Remove Alias"
$btnRemoveAlias.Size = New-Object System.Drawing.Size(120, 30)
$btnRemoveAlias.AutoSize = $false
$btnRemoveAlias.Margin = New-Object System.Windows.Forms.Padding(3, 3, 3, 3)
$btnRemoveAlias.Add_Click({
if ($script:listView.SelectedItems.Count -gt 0) {
$selectedItem = $script:listView.SelectedItems[0]
$selectedAlias = $selectedItem.Text
# Skip header lines
if ($selectedAlias.StartsWith("===") -or $selectedAlias -eq "" -or $selectedAlias -eq "No aliases found.") {
[System.Windows.Forms.MessageBox]::Show("Please select an alias to remove, not a header.")
return
}
$selected = $selectedAlias
$removed = $false
# Try to remove from WindowsApps (App Execution Aliases)
$windowsAppsPath = "$env:LOCALAPPDATA\Microsoft\WindowsApps\$selected"
if (Test-Path $windowsAppsPath) {
try {
# App Execution Aliases are managed by Windows Store apps
# They cannot be directly deleted - inform user
[System.Windows.Forms.MessageBox]::Show("'$selected' is a Windows Store App Execution Alias.`nTo remove it, uninstall the associated app from Windows Settings > Apps.")
return
} catch {
[System.Windows.Forms.MessageBox]::Show("Error: $($_.Exception.Message)")
return
}
}
# Try to remove from App Paths registry
$regPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\App Paths\$selected"
if (Test-Path $regPath) {
try {
Remove-Item -Path $regPath -Recurse -Force
[System.Windows.Forms.MessageBox]::Show("Registry alias '$selected' removed.")
$removed = $true
} catch {
[System.Windows.Forms.MessageBox]::Show("Error removing registry alias: $($_.Exception.Message)")
}
}
# Check custom bin folder
$customBinPath = "$env:USERPROFILE\bin\$selected"
if (Test-Path $customBinPath) {
try {
Remove-Item -Path $customBinPath -Force
[System.Windows.Forms.MessageBox]::Show("Custom alias '$selected' removed from ~/bin.")
$removed = $true
} catch {
[System.Windows.Forms.MessageBox]::Show("Error removing custom alias: $($_.Exception.Message)")
}
}
if (-not $removed) {
[System.Windows.Forms.MessageBox]::Show("Alias '$selected' not found or cannot be removed.")
} else {
$script:btnListAliases.PerformClick()
}
} else {
[System.Windows.Forms.MessageBox]::Show("Please select an alias to remove.")
}
})
$buttonPanel.Controls.Add($btnRemoveAlias)
$btnCreateAlias = New-Object System.Windows.Forms.Button
$btnCreateAlias.Text = "Create Custom Alias"
$btnCreateAlias.Size = New-Object System.Drawing.Size(150, 30)
$btnCreateAlias.AutoSize = $false
$btnCreateAlias.Margin = New-Object System.Windows.Forms.Padding(3, 3, 3, 3)
$btnCreateAlias.Add_Click({
$targetApp = [System.Windows.Forms.OpenFileDialog]::new()
$targetApp.Title = "Select Target Application"
$targetApp.Filter = "Executable files (*.exe)|*.exe|All files (*.*)|*.*"
if ($targetApp.ShowDialog() -eq "OK") {
$defaultName = Split-Path -Leaf $($targetApp.FileName)
$aliasName = [Microsoft.VisualBasic.Interaction]::InputBox("Enter alias name (include .exe extension):`n`nAlias will point to:`n$($targetApp.FileName)", "Create Custom Alias", $defaultName)
if ($aliasName -and $aliasName.Trim() -ne "") {
# Ensure .exe extension
if (-not $aliasName.EndsWith(".exe")) {
$aliasName += ".exe"
}
# Create registry entry in App Paths
$regPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\App Paths\$aliasName"
try {
if (-not (Test-Path $regPath)) {
New-Item -Path $regPath -Force | Out-Null
}
Set-ItemProperty -Path $regPath -Name "(default)" -Value $targetApp.FileName
Set-ItemProperty -Path $regPath -Name "Path" -Value (Split-Path $targetApp.FileName)
[System.Windows.Forms.MessageBox]::Show("Registry alias '$aliasName' created successfully!`nYou can now run '$aliasName' from any command prompt.")
$script:btnListAliases.PerformClick()
} catch {
[System.Windows.Forms.MessageBox]::Show("Error creating registry alias: $($_.Exception.Message)")
}
}
}
})
$buttonPanel.Controls.Add($btnCreateAlias)
# Add resize event to maintain equal left/right margins only
$form.Add_Resize({
$script:listView.Width = $form.ClientSize.Width - 40
# Update column widths proportionally (99% total)
$script:listView.Columns[0].Width = [int](($form.ClientSize.Width - 40) * 0.20) # 20%
$script:listView.Columns[1].Width = [int](($form.ClientSize.Width - 40) * 0.70) # 70%
$script:listView.Columns[2].Width = [int](($form.ClientSize.Width - 40) * 0.09) # 9%
})
# Set initial width correctly based on actual client size
$script:listView.Width = $form.ClientSize.Width - 40
# Update initial column widths (99% total)
$script:listView.Columns[0].Width = [int](($form.ClientSize.Width - 40) * 0.20)
$script:listView.Columns[1].Width = [int](($form.ClientSize.Width - 40) * 0.70)
$script:listView.Columns[2].Width = [int](($form.ClientSize.Width - 40) * 0.09)
# Add form load event to auto-populate aliases
$form.Add_Load({
$script:btnListAliases.PerformClick()
})
# Add form closing event to save window settings
$form.Add_FormClosing({
Save-WindowSettings -Form $form
})
return $form
}
$form = New-Form
[void]$form.ShowDialog()