Adam Mrozek
Adam Mrozek

Reputation: 1480

Getting windows registry editor version

I'm creating an app which should get entire .reg file and then execute it. The registry keys are created by me, my installer works on win XP, 7 and 8. But if I change registry file header to Windows Registry Editor Version 5.00 executing failed on windows XP. This error occurs whenever I change OS and header to another version.

My reg file looks like this:

Windows Registry Editor Version 5.00 //- here is my problem

[HKEY_LOCAL_MACHINE\SOFTWARE\MyApp\myApp]
"DisplayName"="myApp"

[HKEY_LOCAL_MACHINE\SOFTWARE\MyApp2\myFile]
"Directory"="C:\\myFile"

I am interested in .reg file executing only without Registry.CurrentUser.CreateSubKey or similar. Is it standard behavior or I am missing something? Is there some way to retrieve Windows Registry Editor version from C# code?

I'm working with windows 7 in example above. Any help will be appreciated.

Upvotes: 2

Views: 3733

Answers (1)

tamerbak
tamerbak

Reputation: 21

First of all, a .reg file should have the following syntax:

RegistryEditorVersion
Blank line
[RegistryPath1] 
"DataItemName1"="DataType1:DataValue1"
DataItemName2"="DataType2:DataValue2"
Blank line
[RegistryPath2] 
"DataItemName3"="DataType3:DataValue3"
Blank line

In Windows 2000 and later, the file begins with "Windows Registry Editor Version 5.00" (so that line should not make troubles), while earlier versions began with "REGEDIT4".

So make sure you have the right .reg file format (with Blank lines!), and try to use System.Text.Encoding.Unicode encoding while reading your files.

Upvotes: 2

Related Questions