Archive: Registry import by shell command "reg import"


Registry import by shell command "reg import"
Hello!

I tried to add some registry keys using a reg file.
The syntax for the shell command looks e.g. like this:

REG IMPORT d:\regfile\regfile.reg
Now the problem is, if I use that in my NSIS script, it just won't work. But I copied that command out of the "detail view" and just pasted it into a console window, and it worked perfectly.

So the command in my script must be 100% correct, but it doesn't get executed correctly. I used the following syntax:

ExecWait '"REG IMPORT d:\regfile\regfile.reg"'
Does anybody know why this doesn't work? And if it's not my fault, is there any alternative to this command?

Nice greetings
Guv'nor

I'll have to add:

The file is extracted into the right place before the command is executed, so there shouldn't be a "file not found error" or something...


Now I tried exporting the status message into a textfile using

REG IMPORT d:\regfile\regfile.reg > c:\test.txt
and it works perfectly in the command shell. But with the installer, test.txt is not even created... very strange, isn't it?

REG is not an executable. ExecWait requires a full executable path.

Use ExecShell on "d:\regfile\regfile.reg", or use ExecWait on '"$WINDIR\regedit.exe" "d:\regfile\regfile.reg"'
However, you should never use a .reg file. Use NSIS's WriteRegStr, WriteRegDWORD etc

You can use this to generate the script:
http://nsis.sourceforge.net/Reg2Nsis..._NSIS_commands

-Stu


Okay it works now, thank you! I used ExecShell. But why shouldn't you use a regfile? I think it's more flexible somehow...


It's easier for the developer, but it's not professional. You should also have RegEdit displaying a message box asking you to confirm, which is something the user may cancel.

If your reg file is say version 5, it may not work on older versions of Windows. By using NSIS's registry instructions, you're benefited to know that it'll work on all Windows versions.

-Stu