Command: GoRegistry (open reg-key by button or path-field)

Introduction:
GoRegistry is a script command to directly open registry keys from buttons, clipboard or any DO location field in regedit.exe. GoRegistry will open the registry editor for you at the given path and also select sub-keys (if available) automatically. There is an optional retry requester if things went wrong. Registry paths in DO location fields (where you enter the path to your folders) are auto-detected. Notice, that the required event for this, needs to be enabled in the script config first.

Features:

  • expands the registry branch and selects sub-key automatically
  • handles upper/lowercase registry paths and parses keys from bad input
  • optional retry/redo requester
  • optional detection of registry paths in location fields
  • "auto"-mode to use regular method for expanding registry branches and sendkey method for invald ones
  • debug output for trouble shooting
  • some minor options, watch script config dialog for more
  • all script config are available for command line usage as well (but some default to false contrary to the default script config)

Demo: Retry requester for invalid / nonexisting keys and best match mode:



Hints:
After changing settings, please wait 10 seconds for DO and the script to apply changes (especially if you de/activate the option to watch location fields).
The event for this is correctly de/registered, not just consumed and returned if the option is disabled, so it's worth the little delay I think.


Button-Usage:
Create a button similar to the following. When used, it opens the registry path currently in the clipboard.

<?xml version="1.0"?>
<button backcol="none" display="both" textcol="none">
	<label>GoRegistry</label>
	<tip>Open registry editor with path from clipboard</tip>
	<icon1>#registry</icon1>
	<function type="normal">
		<instruction>GoRegistry REQUESTER BESTMATCHAUTO PATH={clip}</instruction>
	</function>
</button>

Location-Field-Usage:
If you'd like to autodetect registry paths in location fields, enable the "WatchLocationFields" option in the scripts config section first.
Then have a lister and paste the registry key/path into the regular location field:



Hit enter and the registry editor pops up (also path of lister is restored):


Installation:
To install the script, download the *.js.txt file below and drag it to Preferences / Toolbars / Scripts.
Do not rename the script to anything that does not match "GoRegistry.js" or edit line #1 in the script.

I hope it works for you, please let me know if it does not! o)
cya, tbone

Updates:
Please send changes and updates directly to me. I will include these in the download right here and won't forget any credits. o)
mb_code a#t steax.net

Download:

2 Likes

Updated to v0.1a

  • minor tweak to fully support HKLM, HKCU etc. in paths (these worked for validating the paths, but not for telling regedit.exe what branch to expand)

Many thanks for providing this script!
I used it to change some Control Panel Icons using registry keys I found on this site: Control Panel - Change Default Icons.
Nircmd.exe can do the same job from a button (Code: [path to]nircmd.exe regedit "{clip}") and I accidentally found, that it's much more fault tolerant than your script. The CLSID string for Network and Sharing Center from the above mentioned site contains an "O" instead of a "0" so your script failed while nircmd.exe was able to open the correct path. It also ignores uppercase/lowercase and works with short and long paths like HklM or hkey_Local_machine. In fact nircmd.exe seems to always try to open a path even if it contains some nonsense (which may be a downside sometimes).

Edit: Removed script code of a modified version of tbone's script that used nircmd.exe to open regedit.

Nircmd.exe can handle reg-keys containing a subkey with a command like this: nircmd.exe regedit "HKEY_CURRENT_USER\Control Panel\Desktop" "Wallpaper". It navigates to the subkey and highlites it.

Edit: Removed script code of a modified version of tbone's script that used nircmd.exe to open regedit and highlites subkeys.

@tbone:
I don't think my nircmd version is the better way to do the job. It just provides some advantages to me at the moment. It's also better than my old nircmd-button because it automatically handles reg-keys with subkey like HKCU\Control Panel\Desktop\Wallpaper and adds the possibility to paste the key into the location bar.

What I'd really wish to have without having to use an external tool is this:

  • A button version of your script because working with the registry is not an every day job for most people and an event that's triggered with every folder change may be too much for this function.
  • Being able to paste a reg-key directly into location bar is on the other hand a really cool feature. A button that enables/disables the script by setting a variable could be a good solution to enable this only when needed.
  • A dialog box that (optionally) opens if the path is invalid could be useful especially for a button version to be able to edit the clipboard content (Buttons: Try again|Guess|Cancel).
  • Automatic subkey highlighting for keys with subkey like nircmd can do would be nice. Any addition to a valid reg-key (separated by backslash, comma, semikolon, space...) could be checked if it's an existing subkey.
  • If a path is invalid fall back to the last valid part of the path. "Guessing" the right path like Nircmd does would also be nice. The first invalid part of the path could possibly be analysed to find a key that matches as much of the first valid characters as possible. With this keys containing a simple typo like O instead of 0 could be matched. A message box could inform that this may not be the correct key.

Nircmd.exe does not really check the existence of keys before trying to select something. I added an option to use nircmd.exe nonetheless. Some (all?) of your topics I already did within the last days, not upped yet. What's not done is "match something similar if invalid" - not worth the effort I think. Subkey selection is what I added now, will upload later.

Now that nircmd.exe is no good, I'd like to ask if you edit your code-posts down to , to not confuse others. Thanks! o) For upcoming changes I'd prefer to get them by mail I think. I will always merge these down into the current download, as I find multiple code blocks a pain to look through. Any upcoming change should also incorporate existing functionality I guess, as multiple versions help no one in keeping track. Credits won't get lost of course! o)

Updates are welcome right here: code a#t steax.net

Updated to v0.2 - including some of Kundals requirements and suggestions - thanks! o)

  • major change: the script does not activate the "location field"-paste feature by default
  • the required event for the latter is correctly de/registered, to not spoil any resources
  • adds new script command "GoRegistry" to open keys directly from clipboard or textboxes with the help of a button/hotkey
  • more fault tolerant for invalid paths (especially missing childs)
  • sub-keys will be autoselected if the registry editor window is found and popped up in a given time
  • optional usage of nircmd.exe to open the registry and expand/select branches (not recommended)

@Kundal

You cannot really en/disable an event by variable, because DO checks what events a script likes to consume at script-load time. You could consume the event in every case and just do nothing in the code, for when you'd like to disable the location-field feature, but then there's no real gain in that. I did not yet notice any delay for handling this event, but just in case anybody runs many scripts/events, every single one creates a delay in the interface, theoretically at least. That's why I had some tests during the last days to find a way of hooking/dehooking the event correctly on script config changes.

Thanks to you for your interest and contribution! o)

Updated to v0.2a

  • fix for v11.6.1beta (the new ConfigHelper-Class failed for the latest DO version)

I tested your new version and after some confusion it works fine now.
Remaining issues:

  • When making changes in the script config editor I always get this error message after a few seconds:


  • Autoselection of sub-keys doesn't work if Nircmd is enabled. Nircmd.exe needs the path with subkey converted to "path" "subkey".
  • at the first try the button version didn't provide the same result as the location bar-paste. The button version failed to recognize the sub-key. I got this fixed by adding NOAUTOSELECT to the button code. After activating the button once and removing the argument it's working fine now.
  • the message box always appears under the regedit window. Would be nice to have it on top. I'd prefer to have a dialog box with a text box showing the reg-key. With this I could edit the content and try again in case there's a typo or some accidentally copied additional characters.

That's the external "touch" to the scriptfile to make DO reload it, it fails for you, so I guess you renamed it!? o)

I actually see no reason to use nircmd, so I did not work on getting sub-keys to work with nirmcd.
Separately given subkeys is something I did not come across yet, so I guess that's quite rare?
And you can always remove any gap between key/sub-key easily right before, don't you?

Yes, it's a DO dialog, that's why. I guess I could use a wsh-native one to get around that, will have a try.

Mhh, I'll have a look.

Thanks for trying! o)

No I didn't but I should have. I used the original downloaded file with .txt extension. :smiley:

The only reason left to use nircmd would be a reg-key with a typo like this example that contains an O instead of 0: HKEY_CLASSES_ROOT\CLSID\{8E908FC9-BECC-40f6-915B-F4CA0E70DO3D}\DefaultIcon. If Regedit falls back to show HKEY_CLASSES_ROOT\CLSID it's a pain in such a case to scroll down to the correct key. For me it would be nice if the script only falls back to use nircmd if nircmd is enabled and the key is invalid.

Doesn't seem to be necessary. A DOpus.Delay(500); works fine here. That also makes it easy to use a dialog box instead of the simple message box. The buttons could be Try again, Cancel and (only if a valid path for nircmd was found) Use Nircmd. That would be possibly the best way to integrate nircmd at all making the NIRCMD argument unnecessary.

Mmhh... the DOpus.Delay (500) opens the message box onTop only with the button version but not with the paste-to-path-field version...

Testing the Delay thing a bit more I found that it works fine if MessageBox is enabled in the script config. When disabled I although always get a message box but without the delay and therefore not onTop.

Isn't it easier just to use regjumper (http://www.sordum.org/8110/registry-key-jumper-v1-1/) to open registry keys from the clipboard.

You can have a button that opens regjumper and then press the regjumper hotkey to open the key in the clipboard in the registry

@goselito
Maybe, but you'd miss the challenge to do it on your own! o) Seriously, I guess RegJumper has some other flaws, and adds a dependency for opening regedit from DO.

@Kundal

I wasn't aware DO also executes *.txt files, in this case yes, please rename the scriptfile. The error is gone now?

I think I got closer to what your (very detailed o) desires are. MsgBox is now always ontop of RegEdit, Retry-Mode works and handling is totally equal now between button/location-field launch, as the location field triggers the GoRegistry command itself from extern (dopusrt.exe), to not block the event from returning. I have the feeling this works quite good now, it actually makes fun re/trying for keys. It's like a game now. o)

Regarding nircmd, I kind of feel like getting rid of it completly, as it does help a bit only for really trashed registry keys. I guess what it does is similar to how I select the sub-key. It think it just "types" the key names the same way, so this is probably something I can do too! o) If keys don't exist, then well.. the result should be the same mismatch nircmd gives. Will have some more tries and upload the next days.

Please don't think of any new functionality, I have real work to do (just kidding)! o))

That was added in v11.5.7 beta. I edited the first line of the script instead of renaming the file because it's very handy for me to be able to open these files by double click. My text editor (EditPad Pro) can be configured to recognize the double extension as JScript file to apply proper syntax coloring. No more errors.

Sounds very promising what you're announcing. I'd be glad to get rid of nircmd. I remember having copied trashed reg-keys from websites several times before. If the script could handle this in a similar (maybe more reliable) way than nircmd that would be great. I think of a routine that for a faulty key like HKEY_CURRENT_USER\Con88trol Panel finds the first key matching HKEY_CURRENT_USER\Con* which would be HKEY_CURRENT_USER\Console. Comparing the result with the input shown in the dialog box would then give you a hint where the faulty character may be. If this could be done it shouldn't result in complete nonsense but open a key as near as possible to the correct key in the tree.

An issue with the current version:

  • When I enable WatchLocationFields in script editor and exit/restart DOpus pasted keys are not recognized any longer although the option shows true. I always have to disable-->save-->re-enable the option to make it work again.

The problem with DOpus.Delay was my fault. I inserted a semi-colon instead of a comma at the end of the line.

Updated to v0.3

  • major internal improvements (location field feature makes use of GoRegistry command itself to detach correctly eg.)
  • best match mode like "nircmd.exe" (nircmd.exe not used/required anymore)
  • better regkey detection from given input
  • retry/redo requester for invalid keys with some options
  • settings not persistent fix

Hint: Add the REQUESTER and BESTMATCHAUTO switches to existing buttons to enhance usability.
Known issue: Retry-Requester does not always get focus, but no way to fix for me (DO issue?).

I think it works quite well, let me know what you think. o)

Wow! I awaited this version eagerly.

Issues:

  • Applying a key to the path field doesn't work for me (Debug message: error on line 138 position2). Changing the line to Dopus.Newcommand.RunCommand(cmd) works fine here. From a button it's also working without that change.
  • Registry keys containing curly brackets aren't working because the bracket isn't recognized as a valid character. Try this example: HKEY_CLASSES_ROOT\CLSID\{8E908FC9-BECC-40f6-915B-F4CA0E70D03D}\DefaultIcon

Apart from these issues everything works great even with typos in the path. One job less for good old NirCmd. :smiley:
Really great work! Many thanks. :thumbsup:
Btw: What's the difference between BESTMATCH and BESTMATCHAUTO?

Suggestion: change the first line to this: var SCRIPTFILENAME = "Command.Generic_GoRegistry.(js|js.txt)"; to make AfterConfig working for .js and .js.txt extension.

Edit:
Another suggestion: I changed lines 304 and 320 to this: dlg.buttons = "Retry Best Match Auto|Retry Strict|Retry Best Match|Cancel";. This is only to blow up the dialog width because it's always a pain to read/edit long strings in a text field. Makes sense for me because reg-keys are often very long strings.

Updated to v0.3.1

  • stretched requesters
  • handling of special characters in registry paths
  • the script now looks for GoRegistry.js to find itself (no need to remove *.txt extension anymore)
  • fix for DO installations with blanks in the path and minor tweaks

Thanks Kundal for testing, reporting and your suggestions, I think those really make sense! o)

Would you mind testing if "applying a key to the path field doesn't work for me" works now for you? I cannot really let you use Dopus.Newcommand.RunCommand(cmd) to trigger GoRegistry, it surely blocks the event chain of DO. o) The issue should be gone if I guessed correctly what went wrong for you.

Thx! o)