Shared INI and Dir Hotlist
Moderators: Hacker, petermad, Stefan2, white
Shared INI and Dir Hotlist
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!
For example:
Location: "HKCU\Software\Microsoft\CurrentVersion\Explorer\User Shell Folders"
Key: "Desktop"
Value: "D:\Users\{username}\Desktop"
Suggestions?
Thanks!
Environment variables can help:
For other variables, take a look at "set" command on a CMD.
Regards
Dalai
Code: Select all
cd "%UserProfile%\Desktop"
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
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64
Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
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:
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:
The only limitation of this way is that there will be no check near this hotlist menu item when you're in this folder.
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%"
Code: Select all
"%COMMANDER_PATH%\cd_shellfolder.bat" "Desktop"
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 postMVV 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.

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
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64
Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
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...
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
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: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
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"

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
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64
Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
PowerShell: Read value Registry Env var. Open in TC.
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.
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:
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.
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%"
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.
Yes, I'm aware of that.MVV wrote:Dalai,
Batch processor starts much faster than PowerShell [...]
It's a simple task, but it's not easy to solve in Batch!and such a simple task may be easilly done with it, so why don't do it?
No, it doesn't, neither on XP nor on Win7. Output from Win7 x64 (64 bit CMD):This one works with spaces too:
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"
[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%"
[/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
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64
Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
Dalai,
Oops, I've posted debug version, it should be 3* and not 2* in a batch. I've corrected my post. Thank you!
Oops, I've posted debug version, it should be 3* and not 2* in a batch. I've corrected my post. Thank you!
