[SOLVED] Not getting proper output when running reg.exe

blueelvis

BSOD Kernel Dump Senior Analyst
Joined
Apr 14, 2014
Posts
970
Location
India
Hi,

I am trying to develop a program and below is the part of source code for it -
Code:
using (Process uninstallListx64 = new Process())            {
                if (File.Exists(systemDrive + @"Windows\SysWow64\reg.exe"))
                {
                    uninstallListx64.StartInfo.FileName = systemDrive + @"Windows\SysWow64\reg.exe";
                    uninstallListx64.StartInfo.Arguments =
                        @"export HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall " + tempDirectory +
                        @"\uninstallx64.reg";
                    Console.WriteLine(uninstallListx64.StartInfo.Arguments);
                    uninstallListx64.Start();
                    uninstallListx64.WaitForExit();
                    uninstallListx64.Close();
                }
                else
                {
                    Console.WriteLine("reg.exe not found in system");
                }
            }
The problem is that whenever I execute the program, I get the "badRegistryEntry.reg" (Attached) which does not contain the information which I want. When I execute the below command on an Admin CMD, I get the "goodRegistryEntry.reg" (Attached) which is what I require -
Code:
reg export HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall C:\Pranav\goodregistryEntry.reg

Also, I tried using both the reg.exe on my system (i.e. one present in the System32 folder and the other one in the SysWow64) and both when executed in CMD yield same results whereas when executed using the program yield the bad registry file :(

Any idea what might be going on?

I am also attaching the Wow6432Node list. To me, the bad one appears very similar to the list found in the Wow6432Node.


Thanks a lot :)
-Pranav


View attachment 32bitUninstall.txt
View attachment goodRegistryEntry.txt
View attachment badRegistryEntry.txt
 
Try adding /reg:64 to your reg.exe command (or calling into the Wow6432Node key on 64bit systems) to work around the issue. Give it a try to be sure, but I suspect you'd be safe leaving /reg:64 in place even on 32bit systems.

Also, as a general principal which applies to all programming languages, when detecting architecture, make sure to capture correctly all the cases where your app is 32bit on a 32bit system, 64bit on a 64bit system, and 32bit on a 64bit system under WOW64.
 
Try adding /reg:64 to your reg.exe command (or calling into the Wow6432Node key on 64bit systems) to work around the issue. Give it a try to be sure, but I suspect you'd be safe leaving /reg:64 in place even on 32bit systems.

Also, as a general principal which applies to all programming languages, when detecting architecture, make sure to capture correctly all the cases where your app is 32bit on a 32bit system, 64bit on a 64bit system, and 32bit on a 64bit system under WOW64.
Hi Richard ^_^,

First of all, thanks for clearing my doubt :) . Your suggestion worked although there was another small requirement before which that switch (/reg:64) would work. The requirement is that this switch must be given as the last parameter as the argument else it won't work (At least not on my system).

I am using the Environment.Is64BitOperatingSystem to determine which command needs to be executed for the registry export. When I tried the app and checked Task Manager, I saw that the app was running as 32bit process and the output was fine. I don't have a copy of 32bit OS with me (Nor it is available on Azure :( ). While building the app, I have configured the Target CPU as = "Any CPU".

I just tried by building the app for both x86 & x64 and this command was executed successfully.


Once again, thanks a lot :)


-Pranav
 

Has Sysnative Forums helped you? Please consider donating to help us support the site!

Back
Top