0
votes

I know how to do normal registry operations in vb.net, but I am having a very hard time finding any info on how to do the same operations on an offline hard drive. Instead of loading data from the currently loaded registry hive, I want to be able to specify something like e:\windows\system32\config\software as the hive to work with. I know I can use reg.exe to load and unload hives, but it would seem that a cleaner pure code method would be better.

1
Hmm, well this is in c# with api calls, was looking for vb.net. I suppose this is a good starting point, since I have nothing better. Regloadkey will work and I found a half working vb.net example. Anyone know if it is possible to do with microsoft.win32?rerat

1 Answers

0
votes

I know that this is a rather old thread, but I had the same question. I was trying to find the computer name of an offline drive. I already had a cmdline sub that used the process class and for the filename gave it "Cmd.exe" (a simple version at the bottom). This sub handles the command line commands I use in my program. I found out how to read the registry quite easily but didn't know how to do so on an offline hive and after some more research combined with what I already knew this is what I ended up with to retrieve the value of the key I wanted in the loaded hive:

Cmdline("reg load HKLM\offlinesys " & windrv & ":\Windows\system32\config\system") Dim readvalue = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\offlinesys\ControlSet001\Control\ComputerName\ComputerName", "ComputerName", Nothing)

This is a bare bones version of my cmdline sub that just includes the relevant part:

Sub Cmdline(ByVal cmd As String, ByVal excpt As Integer)

  If cmd Is Nothing Then
        Throw New ArgumentNullException(NameOf(cmd))
  End If

  Try
      Dim proc As Process = New Process
      Dim procinfo As New ProcessStartInfo With {
          .Arguments = "/c " & cmd & " 2>&1",
          .FileName = "cmd.exe",
          .RedirectStandardOutput = True,
          .UseShellExecute = False
           }
      proc.StartInfo = procinfo
      proc.Start()
End Try
End Sub