Invalid key name for REG ADD on some PCs

3

1

The following commands work on my PC:

reg add Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa /v everyoneincludesanonymous /t REG_DWORD /d 1 /f
reg add Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters /v restrictnullsessaccess /t REG_DWORD /d 0

However, on some machines it responds with:

ERROR: Invalid key name.
Type "REG ADD /?" for usage.

I'm unsure as to what is different and how I could handle this.

Mark Deven

Posted 2018-09-25T16:11:21.893

Reputation: 1 101

3I would try removing the Computer\ part. – HelpingHand – 2018-09-25T19:21:06.773

Ill try this soon ty – Mark Deven – 2018-09-26T20:09:21.670

Forgot to tell you that that worked. Some PCs need \%computername%\HKEY... – Mark Deven – 2018-10-07T21:30:13.017

Answers

4

According to the help for REG.EXE ADD /? the format of the registry path must start with either a computer name or one of five root key names:

REG ADD KeyName [/v ValueName | /ve] [/t Type] [/s Separator] [/d Data] [/f]

  KeyName  [\\Machine\]FullKey
           Machine  Name of remote machine - omitting defaults to the
                    current machine. Only HKLM and HKU are available on remote
                    machines.
           FullKey  ROOTKEY\SubKey
           ROOTKEY  [ HKLM | HKCU | HKCR | HKU | HKCC ]
           SubKey   The full name of a registry key under the selected ROOTKEY.

If your KeyName value begins with \\ it will be treated as a computer name, otherwise REG.EXE expects one of the ROOTKEY values. Since your command does not begin the path with \\ REG.EXE expects one of the ROOTKEY values. Because Computer is not one of those five values, you get the error:

ERROR: Invalid key name.
Type "REG QUERY /?" for usage.

You can fix your command by either removing the leading Computer\ from the path:

reg add HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa /v everyoneincludesanonymous /t REG_DWORD /d 1 /f

Or by specifying the computer name using the leading slashes:

reg add \\Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa /v everyoneincludesanonymous /t REG_DWORD /d 1 /f

Note: This assumes your computer name is actually "Computer". If it isn't provide its actual name.

I say Reinstate Monica

Posted 2018-09-25T16:11:21.893

Reputation: 21 477

I tried this but still I have faced same "ERROR: Invalid key name.". Then I tried "HKCU" instead of "HKEY_CURRENT_USER" then it is worked for me. This is the sample "REG ADD HKCU\Software\SS64 /v Sample /d "some test data"" which is worked for me and I got from following this https://www.urtech.ca/2018/08/solved-command-line-script-to-add-or-delete-a-registry-entry/.

– Vidu – 2020-01-02T03:48:56.693