I am creating an app for the company I work for which will backup the data for some software we supply. It has options to add SQL databases, folders, files and reg keys to the backup job which are then put into a Zip file. There are also options to restore the backup when required.
I am having a problem with the registry backup and restore. I have been through many iterations of trying to get this to work but I have simplified it in a way that best illustrates my problem that I hope someone can help with.
Essentially I am importing a ".reg" file by using the regedit.exe with command line arguments. I have tried doing this by building it with ProcessStartInfo() but it did not work. So to test the problem I am creating a batch file instead and running it as follows:
File.WriteAllText("ImportReg.bat", "regedit /s /i MyRegFile.reg");
Process.Start("ImportReg.bat");
This however does not work.
The batch file is created successfully and the REG file is valid. Both files are in the same location as the EXE to so I don't think the issue should be with which directory is being used. If I run the batch file myself from this location it successfully imports the registry file. I am a full admin on the machine I am testing this on.
I have also had issues with exporting from the registry. Some parts of the registry export fine and others don't. However, if I set the export up as a batch file like the import above then it works every time.
Can anyone help with this? I cannot see why my batch file works, but not when it's run via Process.Start. Any suggestions would be massively appreciated.
Could it be a permissions issue?
Regedit is automatically elevated when you double-click on it. But when running through your program, it is not. Perhaps that's why it lets you export some parts of the regiistry, but not others.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With