gIssue: elevate command which contain path with space
Hyderman opened this issue · comments
Hyderman commented
gsudo v2.0.6
windows 22h2
pwsh 7.3.4
When I elevate the shell I have no problem but if I write sudo/gsudo before my command I got an error if my path contain a space.
My command:
$hexified = "00,00,00,00,00,00,00,00,02,00,00,00,1d,00,3a,00,00,00,00,00".Split(',') | % { "0x$_"};
$kbLayout = 'HKLM:\System\CurrentControlSet\Control\Keyboard Layout';
gsudo --debug { New-ItemProperty -Path $kbLayout -Name "Scancode Map" -PropertyType Binary -Value ([byte[]]$hexified); }
Error Message:
Debug: Invoking Shell: PowerShellCore
Debug: Command Line: --debug -encodedCommand IABOAGUAdwAtAEkAdABlAG0AUAByAG8AcABlAHIAdAB5ACAALQBQAGEAdABoACAAJABrAGIATABhAHkAbwB1AHQAIAAtAE4AYQBtAGUAIAAiAFMAYwBhAG4AYwBvAGQAZQAgAE0AYQBwACIAIAAtAFAAcgBvAHAAZQByAHQAeQBUAHkAcABlACAAQgBpAG4AYQByAHkAIAAtAFYAYQBsAHUAZQAgACgAWwBiAHkAdABlAFsAXQBdACQAaABlAHgAaQBmAGkAZQBkACkAOwAgAA== -inputFormat xml -outputFormat text
Debug: Command to run: "C:\Program Files\PowerShell\7\pwsh.exe" -NoLogo -NoProfile -encodedCommand IABOAGUAdwAtAEkAdABlAG0AUAByAG8AcABlAHIAdAB5ACAALQBQAGEAdABoACAAJABrAGIATABhAHkAbwB1AHQAIAAtAE4AYQBtAGUAIAAiAFMAYwBhAG4AYwBvAGQAZQAgAE0AYQBwACIAIAAtAFAAcgBvAHAAZQByAHQAeQBUAHkAcABlACAAQgBpAG4AYQByAHkAIAAtAFYAYQBsAHUAZQAgACgAWwBiAHkAdABlAFsAXQBdACQAaABlAHgAaQBmAGkAZQBkACkAOwAgAA== -inputFormat xml -outputFormat text
Debug: Using Console mode TokenSwitch
Debug: Caller PID: 2652
Debug: Caller SID: S-1-5-21-4011527363-3575046421-2635246304-1001
Debug: Elevating process: C:\Users\logan\scoop\apps\gsudo\2.0.6\gsudo.exe --debug gsudoelevate 2652 S-1-5-21-4011527363-3575046421-2635246304-1001 All 00:00:00
Debug: Service process started.
Debug: Connected via Named Pipe ProtectedPrefix\Administrators\gsudo_DE9702F86855BB1D7F7F45A68F5530B0DC8885787A1726E998DB81CFD2E1C667.
Debug: CreateProcessAsUserWithFlags: "C:\Program Files\PowerShell\7\pwsh.exe" -NoLogo -NoProfile -encodedCommand IABOAGUAdwAtAEkAdABlAG0AUAByAG8AcABlAHIAdAB5ACAALQBQAGEAdABoACAAJABrAGIATABhAHkAbwB1AHQAIAAtAE4AYQBtAGUAIAAiAFMAYwBhAG4AYwBvAGQAZQAgAE0AYQBwACIAIAAtAFAAcgBvAHAAZQByAHQAeQBUAHkAcABlACAAQgBpAG4AYQByAHkAIAAtAFYAYQBsAHUAZQAgACgAWwBiAHkAdABlAFsAXQBdACQAaABlAHgAaQBmAGkAZQBkACkAOwAgAA== -inputFormat xml -outputFormat text
Debug: Process token successfully substituted.
New-ItemProperty: Cannot bind argument to parameter 'Path' because it is null.
Debug: Process exited with code 1
If I elevate my shell before my command I have no problem, I tried with sudo {cmd} not working too.
Gerardo Grignoli commented
Check the Usage on PowerShell docs.
The command to elevate will ran in a different process, so it can't access the parent $variables and scope.
# Pass arguments with -args $MyString = "Hello World" gsudo { Write-Output $args[0] } -args $MyString
This is what you are looking for (I replaced the $variables
with $args[]
)
$hexified = "00,00,00,00,00,00,00,00,02,00,00,00,1d,00,3a,00,00,00,00,00".Split(',') | % { "0x$_"};
$kbLayout = 'HKLM:\System\CurrentControlSet\Control\Keyboard Layout';
gsudo --debug { New-ItemProperty -Path $args[0] -Name "Scancode Map" -PropertyType Binary -Value ([byte[]]$args[1]); } -args $kbLayout, $hexified