In addition to the Unicode plug-in test TAKE 2,
I found out that ${registry::RestoreKey} is not waiting to return till the process of restoring the key is finished. Which has the potential to give random results when a .reg file to be restored is a fair size and/or additional registry handling is being done straight after restoring the .reg file(this is what PAL will do if there is more then one key to back-up/delete)!
Here is a copy of the ${registry::RestoreKey} source in C.
As you can see in the source, all it does is executing regedit.exe.
So I'm proposing to change this routine into NSIS script ?
There are a couple of ways to go about this, but I want to keep in mind what JTH wrote about using the nsexec plug-in, a while back !
After some testing I came up with the following, to mimic the C script:
- ExecDos plug-in:
SearchPath $9 "regedit.exe" ExecDos::exec `"$9" /s "$DataDirectory\settings\$0.reg"` Pop $R9 ${If} $R9 0 ...
- ProcFunc.nsh :
SearchPath $9 "regedit.exe" ${Execute} `"$9" /s "$DataDirectory\settings\$0.reg"` `` $R9 ${ProcessWaitClose} "$R9" "-1" $8 ${If} $R9 = 0 ...
- ExecWait :
SearchPath $9 "regedit.exe" ExecWait `"$9" /s "$EXEDIR\testHKLM.reg"` $R9 ${If} $R9 0 ...
1. Is the most simple solution, but I'm not sure if JTH agrees with ExecDos instead of nsexec plug-in ?
2. Is basically doing the same as the C script(CreateProcess()), but waiting for the process to finish
3. This option seems even simpler then 1, see below about return values !
Optionally I could include ProcessWaitClose into the C script, here is a small script what could do it in C
Return values for the different routines:
All routines return success even if trying to restore HKLM in a guest account ! The error-flag will be set by 'SearchPath' if the file cannot be found. However, this will be undone straight after using ExecDos/nsexec or ${Execute}. The error flag won't be set if the restoring is unsuccessful, for any of the proposed routines ! nsExec::Exec reg.exe return values: 0 = success 1 = .reg file not found error = reg.exe not found nsExec::Exec regedit.exe return values: 0 = success (even if .reg file is not found) error = regedit.exe not found ExecDos::exec reg.exe return values: 0 = success 1 = .reg file not found -14 = reg.exe not found ExecDos::exec regedit.exe return values: 0 = success (even if .reg file is not found) -14 = regedit.exe not found ProcFunc.nsh, ${Execute} regedit.exe return values: 0 = regedit.exe not found / failed to create process PID = process ID is returned / success (even if .reg file is not found) ${ProcessWaitClose} returns valus (probably not usable): -1 = operation timed out 0 = process does not exist PID = process ID of ended process (is identicle to the PID supplied to ${ProcessWaitClose}) ExecWait regedit.exe return values: 0 = success (even if .reg file is not found), error flag is untouched ! = unsuccessful, string is untouched & error flag is set ExecWait reg.exe return values: This doesn't seem to be an option cause there is no switch to set it to SILENT !