Programmatically merge a .reg file into a win32 registry

What is the best way to programmatically merge a .reg file into a registry? This is for unit testing; A .reg file is a test artifact that will be added and then deleted at the beginning and end of testing.

Or, if there is a better way to unit test to the registry ...

+5
source share
5 answers

You can delete registry keys using a REG file, although I'm not sure how well it is documented. Here's how:

REGEDIT4

[-HKEY_CURRENT_USER\Software\<otherpath>]

-before the key name indicates Regeditthat you want to delete the key.

To start it silently, type:

regedit /s "myfile.reg"
+8
source

, reg ( . ). , , , .

C: > reg/?

REG [ ]

[QUERY | | | |               | | | |               | | | FLAGS]

: ( REG COMPARE)

0 - 1 -

:

REG ADD/? REG DELETE/? []

+5

, .

, .reg regedit.exe Windows.

, regedit.exe "mytest.reg". , , .

+2

Win32 API ShellExecute() ShellExecuteEx(). "", .reg. , .

+1

, , . , Test-Driven Development, , , . , ?

When I find myself asking questions such as this, I look for ways to separate the code that I write from the dependency. Separate your registry reading from the complexity you want to test.

0
source

All Articles