Toolbar button, Start Path with Powershell

English support forum

Moderators: Hacker, petermad, Stefan2, white

Post Reply
User avatar
wanderer
Power Member
Power Member
Posts: 1644
Joined: 2003-03-28, 14:35 UTC
Location: Sol

Toolbar button, Start Path with Powershell

Post by *wanderer »

The following starts PowerShell 1.0 but does not set the start path. Anybody knows why? Setting it to a fixed one, like "C:\Windows" works fine.

I tried the path with and without quotes, no luck. Also, this version of PS does not seem to support -WorkingDirectory command-line parameter. Is there another?

Code: Select all

TOTALCMD#BAR#DATA
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

%P:~0,-1

-1
- Wanderer -

¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Normally using latest TC on:
x32: WinXPx32 SP3 (very rarely nowadays).
x64: Clients/Servers - Win10/Win11 and Win2K16 to Win2K22, mainly Win10 though.
User avatar
wanderer
Power Member
Power Member
Posts: 1644
Joined: 2003-03-28, 14:35 UTC
Location: Sol

Re: Toolbar button, Start Path with Powershell

Post by *wanderer »

OK, to partly answer my question, a workaround is this:

Code: Select all

TOTALCMD#BAR#DATA
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
-NoExit -Command "cd '%P:~0,-1'"
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe



-1
Still, why the button in my OP does not work without a fixed location? Are parameters not supported in Start Path?
- Wanderer -

¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Normally using latest TC on:
x32: WinXPx32 SP3 (very rarely nowadays).
x64: Clients/Servers - Win10/Win11 and Win2K16 to Win2K22, mainly Win10 though.
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50817
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: Toolbar button, Start Path with Powershell

Post by *ghisler(Author) »

Indeed parameters like %P are only supported in the "Parameter" field.
Author of Total Commander
https://www.ghisler.com
User avatar
wanderer
Power Member
Power Member
Posts: 1644
Joined: 2003-03-28, 14:35 UTC
Location: Sol

Re: Toolbar button, Start Path with Powershell

Post by *wanderer »

Ah, ok, thanks for the clarification.
- Wanderer -

¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Normally using latest TC on:
x32: WinXPx32 SP3 (very rarely nowadays).
x64: Clients/Servers - Win10/Win11 and Win2K16 to Win2K22, mainly Win10 though.
User avatar
Horst.Epp
Power Member
Power Member
Posts: 7008
Joined: 2003-02-06, 17:36 UTC
Location: Germany

Re: Toolbar button, Start Path with Powershell

Post by *Horst.Epp »

For me, the following button starts in the current TC dir without the need for any tricks.
Using the button context menu, I can also start it as Administrator.

Code: Select all

TOTALCMD#BAR#DATA
C:\Program Files\PowerShell\7\pwsh.exe
-NoExit
C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe
PowerShell in current path

0
-1
Windows 11 Home, Version 24H2 (OS Build 26100.4351)
TC 11.55 RC6 x64 / x86
Everything 1.5.0.1395a (x64), Everything Toolbar 1.5.5.0, Listary Pro 6.3.2.88
QAP 11.9.0.3 x64
User avatar
Dalai
Power Member
Power Member
Posts: 10016
Joined: 2005-01-28, 22:17 UTC
Location: Meiningen (Südthüringen)

Re: Toolbar button, Start Path with Powershell

Post by *Dalai »

To start something with the current path as working directory just leave the Start Path empty.
#101164 Personal licence
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64

Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
User avatar
wanderer
Power Member
Power Member
Posts: 1644
Joined: 2003-03-28, 14:35 UTC
Location: Sol

Re: Toolbar button, Start Path with Powershell

Post by *wanderer »

Dalai wrote: 2025-05-25, 09:59 UTC To start something with the current path as working directory just leave the Start Path empty.
Yup. Nice, except if you want to start it "as admin" and you have put a * in front of the executable. Then you've lost... :)
- Wanderer -

¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Normally using latest TC on:
x32: WinXPx32 SP3 (very rarely nowadays).
x64: Clients/Servers - Win10/Win11 and Win2K16 to Win2K22, mainly Win10 though.
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50817
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: Toolbar button, Start Path with Powershell

Post by *ghisler(Author) »

The current directory set via SetCurrentDirectory is not passed to programs run as administrator. This is true for all programs, not just for powershell.
Author of Total Commander
https://www.ghisler.com
User avatar
beb
Power Member
Power Member
Posts: 592
Joined: 2009-09-20, 08:03 UTC
Location: Odesa, Ukraine

Re: Toolbar button, Start Path with Powershell

Post by *beb »

2wanderer
Use $pwd. It works both with the button context menu and with * in front of the executable.

Direct-action buttons examples with the asterisk (no as admin option in the context menu though) to run as admin in $pwd:

Code: Select all

TOTALCMD#BAR#DATA
*C:\Program Files\PowerShell\7\pwsh.exe -NoExit

C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe
PowerShell as admin in the current active pane path
cd $pwd
0
-1

Code: Select all

TOTALCMD#BAR#DATA
*C:\Program Files\PowerShell\7\pwsh.exe -NoExit
-c cd $pwd
C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe
PowerShell as admin in the current active pane path


-1
Contex-menu action button example to run As Admin in $pwd:

Code: Select all

TOTALCMD#BAR#DATA
C:\Program Files\PowerShell\7\pwsh.exe -NoExit

C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe
PowerShell as admin in the current active pane path
cd $pwd
0
-1
#278521 User License
Total Commander [always the latest version, including betas] x86/x64 on Win10 x64/Android 16
User avatar
Horst.Epp
Power Member
Power Member
Posts: 7008
Joined: 2003-02-06, 17:36 UTC
Location: Germany

Re: Toolbar button, Start Path with Powershell

Post by *Horst.Epp »

ghisler(Author) wrote: 2025-05-25, 10:31 UTC The current directory set via SetCurrentDirectory is not passed to programs run as administrator. This is true for all programs, not just for powershell.
And why does my button above works when I select "As Administrator" from the Button context menu ?
Also, when TC runs already enhanced, the button starts PowerShell as Administrator in the correct path.
Windows 11 Home, Version 24H2 (OS Build 26100.4351)
TC 11.55 RC6 x64 / x86
Everything 1.5.0.1395a (x64), Everything Toolbar 1.5.5.0, Listary Pro 6.3.2.88
QAP 11.9.0.3 x64
User avatar
white
Power Member
Power Member
Posts: 5964
Joined: 2003-11-19, 08:16 UTC
Location: Netherlands

Re: Toolbar button, Start Path with Powershell

Post by *white »

wanderer wrote: 2025-05-25, 10:17 UTC
Dalai wrote: 2025-05-25, 09:59 UTC To start something with the current path as working directory just leave the Start Path empty.
Yup. Nice, except if you want to start it "as admin" and you have put a * in front of the executable. Then you've lost... :)
ghisler(Author) wrote: 2025-05-25, 10:31 UTC The current directory set via SetCurrentDirectory is not passed to programs run as administrator. This is true for all programs, not just for powershell.
I found this not to be true, at least for my Windows 11 system. The current folder is set to c:\windows\system32 when running programs as administrator if the program is located in c:\windows or any of its subfolders. For programs outside c:\windows, the current folder is not changed. For example, the current folder is not set to c:\windows\system32 when running "C:\Program Files\IrfanView\i_view64.exe" as administrator. Nor when copying "cmd.exe" and "en-US\cmd.exe.mui" to a folder outside the windows folder and running cmd.exe located in that folder as administrator.

Edit: Also tested on Windows Vista where it works the same. It seems the behavior was always bound to program within the windows folder.
Post Reply