简体   繁体   中英

Change a Registry Value, then Run an Application, by Using a Batch File

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM