Shared INI and Dir Hotlist

English support forum

Moderators: Hacker, petermad, Stefan2, white

User avatar
kipp
Junior Member
Junior Member
Posts: 4
Joined: 2013-06-05, 16:00 UTC
Location: United States

Shared INI and Dir Hotlist

Post by *kipp »

I am currently using TC on a group of servers. I have the INI in a shared folder so my settings are synced. The one issue I have is the Dir Hotlist. Not all my servers are using the default locations for Docs/Desktop etc. so I want to use the Registry entry for the folder instead of hard set a folder.

For example:
Location: "HKCU\Software\Microsoft\CurrentVersion\Explorer\User Shell Folders"
Key: "Desktop"
Value: "D:\Users\{username}\Desktop"

Suggestions?

Thanks!
User avatar
ts4242
Power Member
Power Member
Posts: 2081
Joined: 2004-02-02, 20:08 UTC
Contact:

Post by *ts4242 »

There is an internal command to open desktop cm_OpenDesktop
User avatar
MVV
Power Member
Power Member
Posts: 8711
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

No, no, cm_OpenDesktop opens virtual desktop with limited functionality.
It is much better using internal TC pseudo-variable:
cd %$DESKTOP%
User avatar
Dalai
Power Member
Power Member
Posts: 10035
Joined: 2005-01-28, 22:17 UTC
Location: Meiningen (Südthüringen)

Post by *Dalai »

Environment variables can help:

Code: Select all

cd "%UserProfile%\Desktop"
For other variables, take a look at "set" command on a CMD.

Regards
Dalai
#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
MVV
Power Member
Power Member
Posts: 8711
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

Dalai,
It is only a default location. But as it was said in first post, it may be changed to some other one, so it is required to ask Windows where actual locations are.

kipp,
In case of Desktop folder you can use just cd %$DESKTOP%, but if you need some other shell folder, you can use following batch file:

Code: Select all

@echo off
if -%1==- echo User Shell Folders value name should be passed. & pause & goto :EOF
set $PATH=
for /f "usebackq tokens=3" %%p in (`reg.exe query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "%~1" ^| find /i "%~1"`) do set "$PATH=%%p"
%COMMANDER_EXE% /O /S /L="%$PATH%"
It will read value from registry and open corresponding folder in TC's active panel. You can call it from directory hotlist's command field, e.g. for Desktop:

Code: Select all

"%COMMANDER_PATH%\cd_shellfolder.bat" "Desktop"
The only limitation of this way is that there will be no check near this hotlist menu item when you're in this folder.
User avatar
Dalai
Power Member
Power Member
Posts: 10035
Joined: 2005-01-28, 22:17 UTC
Location: Meiningen (Südthüringen)

Post by *Dalai »

MVV wrote:Dalai,
It is only a default location. But as it was said in first post, it may be changed to some other one, so it is required to ask Windows where actual locations are.
AFAIK Windows will change the env variable to the new location if necessary. However, you are right that it's better to use %$DESKTOP%; I just didn't think of these pseudo-variables provided by TC. And I was too slow to post ;), but I didn't want to delete my post since it may help other users.

Regards
Dalai
#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
kipp
Junior Member
Junior Member
Posts: 4
Joined: 2013-06-05, 16:00 UTC
Location: United States

Post by *kipp »

Awesome information!! I'm ecstatic. I did not realize that I could do that.

Thanks all!
User avatar
kipp
Junior Member
Junior Member
Posts: 4
Joined: 2013-06-05, 16:00 UTC
Location: United States

Post by *kipp »

MVV,

Your script works wonders. I appreciate your help. I am using it but I have discovered that is will fail when the Key is two words such as My Music. The token will not be 3 but 4.

I am currently trying to modify your script but can't seem to get it right.

My failed attempt...

Code: Select all

rem @echo off 
if -%1==- echo User Shell Folders value name should be passed. & pause & goto :EOF 
set $PATH= 
REM for /f "usebackq tokens=3" %%p in (`reg.exe query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "%~1" ^| find /i "%~1"`) do set "$PATH=%%p" 
for /f "usebackq tokens=*" %%p in (`reg.exe query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "%~1" ^| find /i "%~1"`) do set "TMP=%%p"
set "%TMP=TMP:    =,%"
for /f "tokens=2 delims=," %%p in (%TMP%) do set "$PATH=%%p" 
%COMMANDER_EXE% /O /S /L="%$PATH%"
pause
User avatar
Dalai
Power Member
Power Member
Posts: 10035
Joined: 2005-01-28, 22:17 UTC
Location: Meiningen (Südthüringen)

Post by *Dalai »

Well, I think it'll be a mess trying to solve this with Batch. The use of PowerShell is much simpler here, although I don't know exactly how to do it since I don't use it that often myself.

A starting point could be something like this:

Code: Select all

Get-ItemProperty -path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -name "my pictures"
I don't know how to get the item of interest, but I'm quite certain that the PowerShell guys in this forum will be able to help with that (and the parameter stuff) :).

BTW: Be very carefully how you name your env variables! TMP is not a good choice since it's predefined and contains the path to your temp directory!

Regards
Dalai
#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
Stefan2
Power Member
Power Member
Posts: 4281
Joined: 2007-09-13, 22:20 UTC
Location: Europa

PowerShell: Read value Registry Env var. Open in TC.

Post by *Stefan2 »

 
Get value only (example):

[face=timesnewroman](Get-ItemProperty -path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders")."my pictures"
[/face]C:\Users\stefano\Pictures

- - -


Example use (Call like script.ps1 "argu ment")


[face=timesnewroman]$UserShellFld = (Get-ItemProperty -path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders").$args
Write-Host "Found $args : $UserShellFld" [/face]


- - -



Example PoSh scripts for the above asked issue:


Button or usercmd.ini command:
cmd=PowerShell -NoExit -NoProfile -ExecutionPolicy Bypass
param=D:\rive\path\to\cd_shellfolder.ps1 "wanted value"


For Registry keys:

Code: Select all

# Read value from Registry. Open found path in TC
# Examples usage:
# thisScript.ps1 "argument"
# "%COMMANDER_PATH%\cd_shellfolder.ps1" desktop
# "%COMMANDER_PATH%\cd_shellfolder.ps1" appdata
# "%COMMANDER_PATH%\cd_shellfolder.ps1" "my pictures"
#

Write-Host "Working on HKCU\...User Shell Folders\$args"
$RegKey = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders"
$UserShellFld = (Get-ItemProperty -path $RegKey).$args
Write-Host "Found $args : $UserShellFld"

Write-Host "Open found path in TC:"
$COMMANDER_EXE = (Get-Childitem env:COMMANDER_EXE).Value

# /T Opens the passed dir(s) in new tab(s). 
# /O If Total Commander is already running, activate it and pass the path
# /S Interprets the passed dirs as source/target instead of left/right
# /L= Set path in left window
#
&$COMMANDER_EXE /T /O /S /L=$UserShellFld

For Environment vars:

Code: Select all

# Read value from Environment "SET" variable . Open found path in TC
# Examples usage:
# thisScript.ps1 "argument"
# "%COMMANDER_PATH%\cd_shellfolder.ps1" desktop
# "%COMMANDER_PATH%\cd_shellfolder.ps1" appdata
# "%COMMANDER_PATH%\cd_shellfolder.ps1" HOMEPATH
#

Write-Host "Working on EnvVar $args"

$EnvVarValue = (Get-Childitem env:$args).Value

Write-Host "Open found path in TC:"
$COMMANDER_EXE = (Get-Childitem env:COMMANDER_EXE).Value

# /T Opens the passed dir(s) in new tab(s). 
# /O If Total Commander is already running, activate it and pass the path
# /S Interprets the passed dirs as source/target instead of left/right
# /L= Set path in left window
#
&$COMMANDER_EXE /T /O /S /L=$EnvVarValue

EDIT: added button command, how to call posh.
Last edited by Stefan2 on 2015-06-29, 08:12 UTC, edited 2 times in total.
User avatar
MVV
Power Member
Power Member
Posts: 8711
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

Dalai,
Batch processor starts much faster than PowerShell and such a simple task may be easilly done with it, so why don't do it? :)
BTW passing parameters to PowerShell isn't a less pain than passing them to Batch because of escaping (in apostrophe-quoted strings apostrophes must be doubled, and in double-quoted string dollar sign must be escaped with accent).

kipp,
Yes, it doesn't work with spaces in paths. We need to leave strings after second one without splitting and refer to the tail. This one works with spaces too:

Code: Select all

@echo off
if -%1==- echo User Shell Folders value name should be passed. & pause & goto :EOF
set $PATH=
for /f "usebackq tokens=3*" %%p in (`reg.exe query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "%~1" ^| find /i "%~1"`) do set "$PATH=%%q"
echo %COMMANDER_EXE% /O /S /L="%$PATH%"
And, as Dalai said, be careful with overriding existing envvars (that's why I use dollar sign as a prefix).

Edited at 17:04

Has problems when value name may contain spaces.
Last edited by MVV on 2015-06-29, 14:06 UTC, edited 4 times in total.
User avatar
Dalai
Power Member
Power Member
Posts: 10035
Joined: 2005-01-28, 22:17 UTC
Location: Meiningen (Südthüringen)

Post by *Dalai »

MVV wrote:Dalai,
Batch processor starts much faster than PowerShell [...]
Yes, I'm aware of that.
and such a simple task may be easilly done with it, so why don't do it? :)
It's a simple task, but it's not easy to solve in Batch!
This one works with spaces too:
No, it doesn't, neither on XP nor on Win7. Output from Win7 x64 (64 bit CMD):

Code: Select all

C:\Users\Administrator>for /f "usebackq tokens=2*" %p in (`reg.exe query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "Desktop" ^| find /i "Desktop"`) do set "$PATH=%q"

C:\Users\Administrator>set "$PATH=%USERPROFILE%\Desktop"

C:\Users\Administrator>for /f "usebackq tokens=2*" %p in (`reg.exe query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "My Pictures" ^| find /i "My Pictures"`) do set "$PATH=%q"

C:\Users\Administrator>set "$PATH=REG_EXPAND_SZ    %USERPROFILE%\Pictures"
The first one (without spaces) is correct, but the second one is not. It's completely logical that it doesn't work since it extracts the 3rd and all following tokens, but one needs to start at the 3rd or 4th, depending on the parameter. The only solution to this issue would be to check if there's a space in the parameter passed to the script and increase the token number by one if there is a space.

[ADD]
I was thinking about something like this:

Code: Select all

@echo off
if -%1==- echo User Shell Folders value name should be passed. & pause & goto :EOF
set t=3
echo "%~1"| findstr /R /C:"[ ]" >NUL && set t=4
set $PATH=
for /f "usebackq tokens=%t%" %%p in (`reg.exe query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "%~1" ^| find /i "%~1"`) do set "$PATH=%%p"
echo %COMMANDER_EXE% /O /S /L="%$PATH%"
It is important that there's no space before the pipe to findstr!
[/ADD]

Regards
Dalai
#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
Stefan2
Power Member
Power Member
Posts: 4281
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Post by *Stefan2 »

or add a trailing

set $path=%$path:reg_expand_sz    =%

[face=timesnewroman](four spaces after _SZ for me)
[/face]


It won't hurt on /v "Desktop"

but will remove   'REG_EXPAND_SZ     '     from /v "My Pictures" output.



 
User avatar
Stefan2
Power Member
Power Member
Posts: 4281
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Post by *Stefan2 »

Dalai wrote:echo "%~1"| findstr /R /C:"[ ]" >NUL && set t=4
I like this too :)

Clever one '[face=timesnewroman]&& set t=[/face]'




 
User avatar
MVV
Power Member
Power Member
Posts: 8711
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

Dalai,
Oops, I've posted debug version, it should be 3* and not 2* in a batch. I've corrected my post. Thank you! :)
Post Reply