Skip to content

Commit 19219ed

Browse files
fix(send-to): PUT never ran (Split-Path param-set error on PS 5.1)
The log finally showed it: MKCOL returned 405 (folder exists, fine) then "Split-Path -LiteralPath <f> -Leaf" threw "parameter set cannot be resolved" on Windows PowerShell 5.1, aborting before the upload. Use [IO.Path]::GetFileName() instead. Also make the menu-manager GUI robust: it now self-elevates itself (so the .cmd no longer needs fragile nested-quote RunAs), adds grid columns one by one (AddRange can fail to coerce), and wraps the whole GUI in a try/catch that logs to %TEMP%\ocl-menu-manager.log and shows a MessageBox instead of vanishing behind the hidden console.
1 parent 562ffcb commit 19219ed

3 files changed

Lines changed: 36 additions & 8 deletions

File tree

‎scripts/send-to/windows/send.ps1‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Log "MKCOL ComputerShared -> $mk (curl exit $LASTEXITCODE)"
6767

6868
$ok = 0; $fail = 0
6969
foreach ($f in $files) {
70-
$leaf = Split-Path -LiteralPath $f -Leaf
70+
$leaf = [System.IO.Path]::GetFileName($f) # .NET: no Split-Path parameter-set pitfall on 5.1
7171
$name = [uri]::EscapeDataString($leaf)
7272
$code = & $curl -s -o NUL -w "%{http_code}" -u $cred -T $f "$base/ComputerShared/$name" 2>&1
7373
Log "PUT '$leaf' -> $base/ComputerShared/$name = $code (curl exit $LASTEXITCODE)"
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
@echo off
22
REM ===========================================================================
3-
REM OpenCoperLock - Windows right-click menu manager (GUI, elevated).
3+
REM OpenCoperLock - Windows right-click menu manager (GUI).
44
REM Double-click to open a small window that lists every right-click entry and
5-
REM lets you tick/untick each one. Requests Administrator so it can manage
6-
REM system-wide entries too. Nothing is deleted - toggles are reversible.
5+
REM lets you tick/untick each one. The script asks for Administrator itself
6+
REM (UAC prompt) so it can manage system-wide entries. Nothing is deleted -
7+
REM toggles are reversible.
78
REM ===========================================================================
8-
powershell -NoProfile -ExecutionPolicy Bypass -Command ^
9-
"Start-Process powershell -Verb RunAs -ArgumentList '-NoProfile','-ExecutionPolicy','Bypass','-WindowStyle','Hidden','-File','\"%~dp0windows-context-menu-manager.ps1\"'"
9+
powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0windows-context-menu-manager.ps1"

‎scripts/windows-context-menu-manager.ps1‎

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ function Test-Admin {
2626
}
2727
$IsAdmin = Test-Admin
2828

29+
# Self-elevate (so system-wide HKLM entries are editable). If the user declines UAC we just continue
30+
# un-elevated - HKCU entries still work.
31+
if (-not $IsAdmin -and -not $Console -and $PSCommandPath) {
32+
try {
33+
Start-Process powershell -Verb RunAs -ArgumentList @(
34+
'-NoProfile', '-ExecutionPolicy', 'Bypass', '-WindowStyle', 'Hidden', '-File', "`"$PSCommandPath`"")
35+
exit
36+
} catch { }
37+
}
38+
2939
$verbRoots = @('*\shell', 'AllFilesystemObjects\shell', 'Directory\shell', 'Directory\Background\shell', 'Folder\shell')
3040
$hives = [ordered]@{ 'HKCU' = 'HKCU:\Software\Classes'; 'HKLM' = 'HKLM:\SOFTWARE\Classes' }
3141

@@ -142,7 +152,11 @@ function Show-Gui {
142152
$c2 = New-Object System.Windows.Forms.DataGridViewTextBoxColumn; $c2.HeaderText = "Nom"; $c2.ReadOnly = $true; $c2.FillWeight = 40
143153
$c3 = New-Object System.Windows.Forms.DataGridViewTextBoxColumn; $c3.HeaderText = "S'applique a"; $c3.ReadOnly = $true; $c3.FillWeight = 30
144154
$c4 = New-Object System.Windows.Forms.DataGridViewTextBoxColumn; $c4.HeaderText = "Type"; $c4.ReadOnly = $true; $c4.FillWeight = 12
145-
[void]$grid.Columns.AddRange(@($colOn, $c1, $c2, $c3, $c4))
155+
[void]$grid.Columns.Add($colOn)
156+
[void]$grid.Columns.Add($c1)
157+
[void]$grid.Columns.Add($c2)
158+
[void]$grid.Columns.Add($c3)
159+
[void]$grid.Columns.Add($c4)
146160

147161
function Fill-Grid {
148162
$filter = $txt.Text.Trim()
@@ -250,4 +264,18 @@ function Show-Console {
250264
Write-Host "`nDone. Restart Explorer for changes to apply." -ForegroundColor Green
251265
}
252266

253-
if ($Console) { Show-Console } else { Show-Gui }
267+
if ($Console) {
268+
Show-Console
269+
} else {
270+
try {
271+
Show-Gui
272+
} catch {
273+
# A hidden window would otherwise swallow a startup error - log it AND show it.
274+
$log = Join-Path $env:TEMP 'ocl-menu-manager.log'
275+
try { [System.IO.File]::AppendAllText($log, "$(Get-Date) GUI error: $($_.Exception.ToString())`r`n") } catch { }
276+
try {
277+
Add-Type -AssemblyName System.Windows.Forms
278+
[System.Windows.Forms.MessageBox]::Show("$($_.Exception.Message)`n`nDetails logged to:`n$log", 'OpenCoperLock - GUI error') | Out-Null
279+
} catch { }
280+
}
281+
}

0 commit comments

Comments
 (0)