Showing posts with label Windows. Show all posts
Showing posts with label Windows. Show all posts

May 10, 2012

Windows Registry file (.reg) doesn't register key

It was a nice test for me. I needed to give a .reg file for a collegue of mine (its a long story) to recreate a setting for something we're doing. Long story short - I needed to add a path under a certain key so I did the following:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Key1\SubKey1]
"PathKey1"="C:\SomeFolder\SomeSubFolder\SomeExecutable.exe"
When I ran it on my PC to verify it's working I saw it created the keys all the way to the "SubKey1" but the string value PathKey1 wasn't added. Can you say what the problem was? I wasn't sure as well. Then I've found you have a nifty little menu option in registry that says "Export" and it will create the reg file for you. I ran it and out of curriosity I opened the file in Notepad to see what was I missing. The thing is that RegEdit want to have the "\" escaped with another "\" so the successfull reg file will be:
Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Key1\SubKey1]
"PathKey1"="C:\\SomeFolder\\SomeSubFolder\\SomeExecutable.exe"
The catch here is that no matter RegEdit won't be able to create the String value it will tell you that it succeeded. I will most probably never use to manually add things in Notepad, I'll use Regedit Export functionality now that I know it but be sure to always check that paths added to the registry via .reg file are double escaped. Hope this helps.