Repository navigation
Expand file tree
/
Copy pathAddToContextMenu.ps1
More file actions
106 lines (91 loc) · 4.35 KB
/
Copy pathAddToContextMenu.ps1
File metadata and controls
106 lines (91 loc) · 4.35 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
# Script to add the FileMoveCopy tool to Windows Explorer context menu
$moveScriptPath = Join-Path $PSScriptRoot "FileMove.ps1"
$copyScriptPath = Join-Path $PSScriptRoot "FileCopy.ps1"
$iconPath = "powershell.exe" # Use PowerShell icon
# Function to add context menu for files - Move
function Add-FileMoveContextMenu {
$keyPath = 'Registry::HKEY_CLASSES_ROOT\*\shell\MoveFiles'
if (!(Test-Path -LiteralPath $keyPath)) {
New-Item -Path $keyPath -Force
}
Set-ItemProperty -LiteralPath $keyPath -Name "(Default)" -Value "Move Files"
Set-ItemProperty -LiteralPath $keyPath -Name "Icon" -Value $iconPath
$commandKey = "$keyPath\command"
if (!(Test-Path -LiteralPath $commandKey)) {
New-Item -Path $commandKey -Force
}
$command = "powershell.exe -ExecutionPolicy Bypass -File `"$moveScriptPath`" `"%L`""
Set-ItemProperty -LiteralPath $commandKey -Name "(Default)" -Value $command
}
# Function to add context menu for files - Copy
function Add-FileCopyContextMenu {
$keyPath = 'Registry::HKEY_CLASSES_ROOT\*\shell\CopyFiles'
if (!(Test-Path -LiteralPath $keyPath)) {
New-Item -Path $keyPath -Force
}
Set-ItemProperty -LiteralPath $keyPath -Name "(Default)" -Value "Copy Files"
Set-ItemProperty -LiteralPath $keyPath -Name "Icon" -Value $iconPath
$commandKey = "$keyPath\command"
if (!(Test-Path -LiteralPath $commandKey)) {
New-Item -Path $commandKey -Force
}
$command = "powershell.exe -ExecutionPolicy Bypass -File `"$copyScriptPath`" `"%L`""
Set-ItemProperty -LiteralPath $commandKey -Name "(Default)" -Value $command
}
# Function to add context menu for folders - Move
function Add-FolderMoveContextMenu {
$keyPath = 'Registry::HKEY_CLASSES_ROOT\Folder\shell\FileMove'
if (!(Test-Path -LiteralPath $keyPath)) {
New-Item -Path $keyPath -Force
}
Set-ItemProperty -LiteralPath $keyPath -Name "(Default)" -Value "Move Folder"
Set-ItemProperty -LiteralPath $keyPath -Name "Icon" -Value $iconPath
$commandKey = "$keyPath\command"
if (!(Test-Path -LiteralPath $commandKey)) {
New-Item -Path $commandKey -Force
}
$command = "powershell.exe -ExecutionPolicy Bypass -File `"$moveScriptPath`" `"%L`""
Set-ItemProperty -LiteralPath $commandKey -Name "(Default)" -Value $command
}
# Function to add context menu for folders - Copy
function Add-FolderCopyContextMenu {
$keyPath = 'Registry::HKEY_CLASSES_ROOT\Folder\shell\FileCopy'
if (!(Test-Path -LiteralPath $keyPath)) {
New-Item -Path $keyPath -Force
}
Set-ItemProperty -LiteralPath $keyPath -Name "(Default)" -Value "Copy Folder"
Set-ItemProperty -LiteralPath $keyPath -Name "Icon" -Value $iconPath
$commandKey = "$keyPath\command"
if (!(Test-Path -LiteralPath $commandKey)) {
New-Item -Path $commandKey -Force
}
$command = "powershell.exe -ExecutionPolicy Bypass -File `"$copyScriptPath`" `"%L`""
Set-ItemProperty -LiteralPath $commandKey -Name "(Default)" -Value $command
}
# Run as administrator check
if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Write-Host "Please run this script as Administrator to modify the registry."
exit
}
# Add the context menus
Write-Host "Adding context menu entries..."
Write-Host " [1/4] Adding 'Move Files' context menu..."
Add-FileMoveContextMenu
Write-Host " [1/4] [OK] 'Move Files' context menu added successfully."
Write-Host " [2/4] Adding 'Copy Files' context menu..."
Add-FileCopyContextMenu
Write-Host " [2/4] [OK] 'Copy Files' context menu added successfully."
Write-Host " [3/4] Adding 'Move Folder' context menu..."
Add-FolderMoveContextMenu
Write-Host " [3/4] [OK] 'Move Folder' context menu added successfully."
Write-Host " [4/4] Adding 'Copy Folder' context menu..."
Add-FolderCopyContextMenu
Write-Host " [4/4] [OK] 'Copy Folder' context menu added successfully."
Write-Host ""
Write-Host "Installation completed successfully!"
Write-Host "Context menu items added. You may need to restart Explorer or log off/log on for changes to take effect."
Write-Host ""
Write-Host "Next steps:"
Write-Host " 1. Restart Windows Explorer (or log off/log on)"
Write-Host " 2. Right-click files/folders to see the new menu options"
Write-Host " 3. Use RemoveFromContextMenu.ps1 to uninstall if needed"