views:

231

answers:

1

I'm writing a program for my workplace and because we work on computers damaged by hard drives we sometimes need to work with their registries before they'll boot.

Most notably, we're trying to fix the 0x7b error that stems from the Registry Hive that controls the default Hard disk drivers being damaged and the computer wont boot.

Microsoft has a Knowledge Base entry on how to do it manually, but we want to automate it. That being said, what's required is that I have to edit the registry hive on a different hard drive.

How can I modify the Registry Hive that is located on a different Hard drive with C#? The other hard drive will contain a complete OS, but will not be currently running.

+1  A: 

I assume that you can read the files on the target drive. You need to use the RegLoadKey() Win32 API (or the .NET quivalent if there is one) to load the hive into a key in the local computer's registry. Manipulate that hive's contents under the key you passed to RegLoadKey().

Then RegUnloadKey().

Read the docs for RegLoadKey() - you might need to muck around with privileges to get things to work properly.

Michael Burr
If the other harddrive was mounted on F:, what would the path I need to supply to access it with RegLoadKey?
Malfist
The registry hives are just regular files (but might have unusual attributes - I can't remember). If I remember right '\windows\system32\config\system' and '\windows\system32\config\software' contain most of the machine-level stuff if I remember right.
Michael Burr
I figured it out. RegLoadKey(0x80000002, "OLD_SYSTEM", "F:\Windows\System32\config\system");
Malfist
You should really use `HKEY_LOCAL_MACHINE` instead of 0x80000002 (make your own enum if there's noththing suitable in the framework if you're doing things in .NET).
Michael Burr