Code: Select all
[em_alias_ps_adm]
cmd=*%$SystemX86%\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -NoExit
param=$A
What I'm doing wrong?
Moderators: Hacker, petermad, Stefan2, white
Code: Select all
[em_alias_ps_adm]
cmd=*%$SystemX86%\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -NoExit
param=$A
Code: Select all
[em_alias_ps_adm]
cmd=powershell -ExecutionPolicy Bypass -NoExit
param=$A
Code: Select all
[em_alias_ps_adm]
cmd=powershell
param=$A
Code: Select all
[em_test_rar_commander_path]
cmd=powershell -c si -path env:path -value $env:path';'$env:commander_path\Utils;
param=rar.exe -?;pause
Code: Select all
[em_test_rar_full_path]
cmd=powershell -c si -path env:path -value $env:path';'D:\Program' 'Files\Total' 'Commander' '64\Utils;
param=rar.exe -?;pause
KozakMak wrote: 2024-11-07, 15:40 UTC Trying: *ps "D:\Program Files\Total Commander 64\Utils\Rar.exe" or any path with spaces - get error like "D:\Program"...
What I'm doing wrong?
Code: Select all
*ps & 'D:\Program Files\Total Commander 64\Utils\Rar.exe'
*ps & '"D:\Program Files\Total Commander 64\Utils\Rar.exe"'
*ps . \"D:\Program Files\Total Commander 64\Utils\Rar.exe\"
Code: Select all
param=%A
Code: Select all
param=$A
That's for sure--all the TotalCommander special parameters such as %WL, %N, %P, %P%N, %S, %P%S, %T, etc., that are intended to be passed from TotalCommander to PowerShell should go in TotalCommander syntax.
Code: Select all
[em_test_tc_params]
cmd=pwsh -c
param=sv t -value '%T';$t;sv p -value '%P';$p;sv n -value '%N';$n;sv pn -value '%P%N';$pn;sv wl -value '%WL';$wl;pause
Code: Select all
[em_test_tc_params_ps1]
cmd=pwsh -c "%commander_path%\Plugins\app\PowerShell\echoParams.ps1"
param=%WL %N %P %P%N %S %P%S %T %C1 %C2
Code: Select all
'arguments breakdown...'|Write-Host -f Green
''
'raw $args value:'|Write-Host -f Yellow
if ($args){"$args"|Write-Host -f DarkCyan}
else {'... no $args have been passed'|Write-Host -f Red}
''
'process first passed parameter as %WL:'|Write-Host -f Yellow
$param = $args[0]
$param|Write-Host -f DarkCyan
if ($param){
foreach ($line in [System.IO.File]::ReadLines($param)){$line|Write-Host -f Cyan}}
else {'... no $args have been passed'|Write-Host -f Red}
''
'list parameters by individual indexes [0]...[8]:'|Write-Host -f Yellow
$param = $args[0];"[0] %WL : $param"
$param = $args[1];"[1] %N : $param"
$param = $args[2];"[2] %P : $param"
$param = $args[3];"[3] %P%N : $param"
$param = $args[4];"[4] %S : $param"
$param = $args[5];"[5] %P%S : $param"
$param = $args[6];"[6] %T : $param"
$param = $args[7];"[7] %C1 : $param"
$param = $args[8];"[8] %C2 : $param"
''
'list all parameters in $args array:'|Write-Host -f Yellow
$total = 0
foreach ($param in $args) {"{0,-8:[0]} : {1}" -f $total,$param;$total++}
''
pause
beb wrote: 2024-11-07, 19:23 UTC Thus, "powershell.exe", or even simply "powershell" would be pretty enough, like this:Code: Select all
[em_alias_ps_adm] cmd=powershell -ExecutionPolicy Bypass -NoExit param=$A
Code: Select all
[em_test_ps_as_admin]
cmd=powershell -c
param=start-process powershell -verb RunAs
Code: Select all
[em_test_ps_adm]
cmd=powershell -c start powershell -verb RunAs
*ps - run powershell as admin with CURRENT path
Ok. Now it's clear. Thank you.KozakMak wrote: 2024-11-08, 08:30 UTC .\my script.ps1 arg1 agr2 ... - run powershell script as admin
Code: Select all
[em_test_ps_adm]
cmd=pwsh -c "c:\script\dummy.ps1"
param='Arg1 Arg2'
Code: Select all
# check if the script is elevated
if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))
{
# preserve script arguments $args automatic variable as $params string variable for future use
[string]$params = $args
'my script is "{0}"' -f $MyInvocation.MyCommand.Path|Write-Host -f Cyan
'my script arguments are "{0}"' -f $args|Write-Host -f DarkCyan
''
'my script is NOT elevated. Relaunching...'|Write-Host -f Yellow
# relaunch as elevated with the $params as script arguments
Start-Process pwsh.exe "-File",('"{0}" {1}' -f $MyInvocation.MyCommand.Path,$params) -Verb RunAs
sleep -s 20 # pausing for 20 seconds to see what's on the pre-relaunch screen
exit
}
''
# now running elevated
[string]$params = $args
'now my script IS ELEVATED...'|Write-Host -f Yellow
''
'checking if the script arguments are still there...'|Write-Host -f Yellow
''
'my elevated script is "{0}"' -f $MyInvocation.MyCommand.Path|Write-Host -f Cyan
'my elevated script arguments are "{0}"' -f $params|Write-Host -f Green
''
pause
Code: Select all
[em_test_ps_adm]
cmd=pwsh -c
param=."\dummy.ps1" 'Arg1 Arg2'
Code: Select all
[em_test_ps_adm]
cmd=pwsh -c
param=."\dummy.ps1" '%P %WL'
Code: Select all
[em_alias_ps]
cmd=powershell.exe -ExecutionPolicy Bypass -NoExit
param=-Command "If ('%A') { & .\%A }"
[em_alias_ps_adm]
cmd=*%$SystemX86%\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -NoExit
param=-Command "cd '%P'; If ('%A') { & .\%A }"
Code: Select all
# check if the script is elevated
if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))
{
'my script is "{0}"' -f $MyInvocation.MyCommand.Path|Write-Host -f Cyan
'my script arguments are "{0}"' -f $args|Write-Host -f DarkCyan
''
'my script is NOT elevated. Relaunching...'|Write-Host -f Yellow
# relaunch as elevated with the "$args" as script arguments
Start-Process pwsh.exe "-File",('"{0}" "{1}"' -f $MyInvocation.MyCommand.Path,"$args") -Verb RunAs
sleep -s 20 # pausing for 20 seconds to see what's on the pre-relaunch screen
exit
}
# now running elevated
''
'now my script IS ELEVATED...'|Write-Host -f Yellow
''
'checking if the script arguments are still there...'|Write-Host -f Yellow
''
'my elevated script is "{0}"' -f $MyInvocation.MyCommand.Path|Write-Host -f Cyan
'my elevated script arguments are "{0}"' -f $args|Write-Host -f Green
''
pause