0

I want to change a registry value (a REG_DWORD), then run an application, by using a batch file, that is located in the same folder as the application. I tried the lines below, but that does not work:

reg add "HKEY_CURRENT_USER\A User Name\An Application Name" /v A value name_h3981298716 /d "99" /t REG_DWORD /f

START %~dp0AnApplicationName.exe

The "START ..." will work without the "reg add ..." code. The batch file can run an application, but it cannot change a registry value of REG_DWORD type.

How to do the sequence below correctly with a batch file?

  1. First, change a registry value of REG_DWORD type.

  2. Then run an application.

3
  • Because there is something wrong. Please be more specific! Commented Nov 29, 2016 at 12:42
  • Try surrounding %~dp0AnApplicationName.exe with double quotes. Whenever a batch file "does not work" place as many useful echoes in there and start it using a command prompt. With that you can check at what point the file failed. Commented Nov 29, 2016 at 13:05
  • The "START ..." will work without the "reg add ..." code. The batch file can run an application, but it cannot change a registry value of REG_DWORD type. Commented Nov 29, 2016 at 13:20

1 Answer 1

1
reg add "HKCU\A User Name\An Application Name" /v "A value name_h3981298716" /d "99" /t REG_DWORD /f

Note that if a value name contains a space then it should be surrounded with double quotes. Keep doing that even if a value name does not contain any space.

Example, with another key name:

==> reg query "HKCU\Software\Test Key" /t reg_dword

End of search: 0 match(es) found.

==> reg add "HKCU\Software\Test Key" /v A value name_h3981298716 /d "99" /t REG_DWORD /f
ERROR: Invalid syntax.
Type "REG ADD /?" for usage.

==> reg add "HKCU\Software\Test Key" /v "A value name_h3981298716" /d "99" /t REG_DWORD /f
The operation completed successfully.

==> reg query "HKCU\Software\Test Key" /t reg_dword

HKEY_CURRENT_USER\Software\Test Key
    A value name_h3981298716    REG_DWORD    0x63

End of search: 1 match(es) found.
Sign up to request clarification or add additional context in comments.

7 Comments

I have surrounded the value name with double quotes, then run the batch file, but the value still does not change.
@Bayu If the value does not change then you should get an error message. Add a pause command immediately below reg add … to see the result. Check success using reg query … in the same way I did in my example.
There was a message after I added "pause" below the "reg add ...":
The message is : "The operation completed successfully". But the value still does not change in the Registry Editor...
In an open registry editor, you need F5 refresh (seen also in the View menu) to see changes made from another process…
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.