Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Registry key name aliases?

May
12,937
171
I use REGDIR and the plugins KEYTIMES and @KEYTIME a lot. It would be nice to be able to type something significantly shorter than, for example, HKLM\SYSTEM\CurrentControlSet\Services\w32tmsvc. My first thought was a plugin, @RK[alias] which would look up the alias in a file and return the full key name. If I structured the file like this

Code:
[w32tm]
name=HKLM\SYSTEM\CurrentControlSet\Services\w32tmsvc
[alias]
name=target key
; et c.

I could easily do the lookup with the function GetPrivateProfileString() (for reading INI-like files).

For the key above, I'd have to type only %@rk[w32tm], 10 characters compared to the full name's 47 characters.

(Second thought) Without a plugin, I suppose I could make real aliases out of them and look them up with @ALIAS. That'd be easy (and it would clutter up my alias list).

Any other ideas? Thanks.
 
Environment variables?
Yeah, I'll try that. I'd have to make a custon SET command so I don't see them unless I want to. The alias thing is working out well.

Code:
v:\> alias w32tm
HKLM\SYSTEM\CurrentControlSet\Services\w32tmsvc\W32TmParams_rk

I put the "_rk" suffix on it so I could filter them.

Code:
v:\> function rk
%@left[-3,%@alias[%1]]

Code:
v:\> echo %@keytime[%@rk[w32tm]]
2023-05-21,03:18:27.9629953

This will probably get refined but, for now, I have this alias for filtering out the directory and regkey aliases.

Code:
v:\> alias al
alias | grep -E -v "_rk$|:="
 
On a vaguely related note:

A plugin can implement new syntax at the command line by hooking the Enter key. When the Enter key is pressed, a plugin can parse the command line and take whatever actions are needed before handing it back the TCC, possibly with changes. But this trick only works at the command line; there is no equivalent for batch files.

Would it make sense to add a plugin hook to intercept lines read in from a batch file? Would anybody use such a feature? Or would it just be asking for trouble?
 
An even better example;
Code:
@setlocal
@echo off
set h=%@hashnew[]
echo Hash Handle: %h
echo.
echo Adding data to hash
echo.
set r=%@hashput[%h,w32tmsvc/HKLM\SYSTEM\CurrentControlSet\Services\w32tmsvc]
set r=%@hashput[%h,JPGlobal/HKCU\JPGlobal]
set r=%@hashput[%h,Volatile/HKCU\Volatile Environment]
echo Getting w32tmsvc
echo.
echo %@hashget[%h,w32tmsvc/]
echo Contents of hash
echo.
hashentries %h
echo.
echo Saving hash to HashTest.hf
echo.
hashfile %h /W HashTest.hf
set r=%@hashfree[%h]

set h=%@hashnew[]
echo Hash Handle: %h
echo Reading HashTest.hf
hashfile %h /R  HashTest.hf
hashentries %h
echo.
echo Getting Volatile
set Volatile=%@hashget[%h,Volatile/]
regdir /d /v %Volatile
set r=%@hashfree[%h]
endlocal

Joe
 
You can use simple powershell hash tables like this:
Code:
test.ps1:
---
param (
    [string]$keyalias
)

$km = @{ 
    w32tm = "HKLM\SYSTEM\CurrentControlSet\Services\w32tmsvc"; 
    tc29 = "HKEY_CLASSES_ROOT\Directory\shell\runas\shell\TC29\command" 
}
echo $km["$keyalias"]
---

echo %@pshell[./test.ps1 w32tm]
function keyalias=`%@pshell[./test.ps1 %1]`

echo %@keyalias[w32tm]
echo %@keyalias[tc29]
 
Hmmm! Aliases are nice because they don't have to be created/loaded. I use global aliases, auto-loaded at logon, protected by SHRALIAS, and auto-saved at logoff/shutdown. They're fast (in memory) and can be edited with ESET (* though I don't foresee much reason to do so).

The environment would probably be faster (no @functions) and involve less typing (%w32tm vs. %@r[w32tm]). But they'd have to be either put in a persistent environment (system or user) or loaded at TCC startup (which I don't like). I could use ESET on them too (*).

I don't like the hash table idea. I reckon it would have to be created or loaded by every instance of TCC.

Another idea: I already have HKCU\JPGlobal and plugins GSET for setting REG_SZ values there and @GV[] for retrieving them. I could put them there. If I put them there, there would be no creating/loading, I couldn't use ESET on them (*). I wouldn't need the UDF @RK because I have the plugin @GV.

Hmmm!

Related: I just stumbled on this ...

Code:
Regjump v1.1
Copyright (C) 2013-2015 Mark Russinovich
Sysinternals - www.sysinternals.com

... forgetting that I already had it. It works just fine, to start REGEDIT at the named key and uses TCC's abbreviations (HKCR, et al.).

REGJUMP is a bit goofy. You can see that it's clicking its way through the registry's tree. But it beats starting REGEDIT and navigating or using favorites.

I could probably use the UNKNOWN_CMD alias to check the global variables (or environment, or aliases, or hash table) and, if (for example) "w32tm" is found use it's value as the argument to REGJUMP. So I'd have the value of %@GV[w32tm] (or %@ALIAS[w32tm], or %w32tm, or %@HASH[w32tm]) to use as needed as well as the command "w32tm" to start regedit.

Just curious ... does anyone use the UNKNOWN_CMD alias?
 
I've used it occasionally as a plugin export. Not as an alias alias, at least not in many years.
Heehee! Check out the date on this file.

Code:
v:\> d p:\4Utils\special_aliases.cpp
2010-07-30  21:55               2777  special_aliases.cpp
 
A first attempt ... AL.BTM ...

Code:
setlocal

iff "%1" == "/d" then
    :: show only directory aliases
    *alias | grep ":="
elseiff "%1" == "/r" then
    :: show only regkey aliases
    *alias | grep "_rk$"
elseiff "%1" == "/k" then
    :: show only keystroke aliases
    *alias | grep "^@"
elseiff "%1" == "" then
    :: show only command aliases
    *alias | grep -E -v "_rk$|:=|^@"
else
    :: normal
    *alias %$
endiff

TCC's regex handling (at least the Perl syntax) handles "alternation" ("pattern|pattern", as above). After only very little testing, piping to FFIND /v /k /m /e"regex" seems a decent substitute for Gnu's grep. But I don't think FFIND can invert a text search (like grep's -v) and give only lines that don't match (hoping I'm wrong about that).
 
This ain't bad.

Code:
v:\> alias mygrep `ffind /v /k /m /e%1`

v:\> mygrep Proxy %_ininame
ProxyPort=80

v:\> type %_ininame | mygrep Proxy
ProxyPort=80

v:\> mygrep "Proxy|Fire" %_ininame
ProxyPort=80
FirewallType=None
FirewallPort=0

v:\> type %_ininame | mygrep "Proxy|Fire"
ProxyPort=80
FirewallType=None
FirewallPort=0
 
This is good to know. The regex ignore_case indicator applies to all patterns in an alternation ...

Code:
v:\> mygrep "(?i)fire|prox" %_ininame
ProxyPort=80
FirewallType=None
FirewallPort=0

... unless otherwise specified.

Code:
v:\> mygrep "(?i)fire|(?-i)prox" %_ininame
FirewallType=None
FirewallPort=0
 
Back
Top