익명 15:39

Setting Registry to automatically opening specific key/folder fails when set by ...

Setting Registry to automatically opening specific key/folder fails when set by batch program

My original goal was to have the Windows Registry Editor open up at a specific key. We tenuously accomplished that. However now there there is a new problem.

The Windows Registry remembers which key was open so it'll show it by default the next time it is opened here:

Computer\HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Applets\Regedit

Using the LastKey key.

In the command prompt reg /? doesn't help, as it turns out we have to use reg add /? for the syntax help. So I took Neil's example and modified it to the following (test.bat):

REG ADD HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Applets\Regedit /v LastKey /t REG_EXPAND_SZ /d "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer" /f
regedit

Now the /f surpresses the confirmation and the value is actually set. The batch program opens the Windows Registry too. The problem is that the Windows Registry just opens up at just Computer.

How do we identify and correct the problem of the Registry no longer utilizing LastKey to automatically open it via the batch file?

For clarification: if I manually go to another key, close the Registry Editor and then open it again manually it will honor LastKey setting. So this issue is, as far as I can determine, specific to the batch program.

Additionally I've started the string with both (which neither works):

  • HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows
  • Computer\HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows


Top Answer/Comment:

Your batch file should look something like this:

@setlocal
@set __COMPAT_LAYER=RunAsInvoker
@reg add HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Applets\Regedit /v LastKey /d "Computer\HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer" /f
@start regedit

Note that the /t flag defaults to REG_SZ (using REG_EXPAND_SZ was wrong) so I have omitted it and you do need to include the Computer\ prefix for the value.

I have added the environment variable which disables Regedit's automatic elevation; if you're editing your own HKEY_CURRENT_USER this shouldn't be necessary, and I find it annoying.

I have also suggested the use of start so that the batch file can close once Regedit has started, rather than having to wait around for it to finish.

상단 광고의 [X] 버튼을 누르면 내용이 보입니다