Skip to content
⌘ NSIS Forum Archive

RequestExecutionLevel user and registry import/export

7 posts

Gluck#

RequestExecutionLevel user and registry import/export

I have this code:

WindowIcon Off
SilentInstall Silent
AutoCloseWindow True
RequestExecutionLevel user

!define APP "MyApp"
!define APPEXE "MyApp"
!define APPNOSPACE "MyApp"


OutFile "..\..\${APP}.exe"
Icon "${APPEXE}.ico"




Section "REGISTRY"

!include "Registry.nsh"

!define REGISTRYKEY1 "HKEY_CURRENT_USER\Software\MyApp"
!define PORTABLEKEY1 "$EXEDIR\User\MyApp.reg"

${registry:😁eleteKey} "${REGISTRYKEY1}-BackupBy${APPNOSPACE}Portable" $R0
Sleep 200

${registry::MoveKey} "${REGISTRYKEY1}" "${REGISTRYKEY1}-BackupBy${APPNOSPACE}Portable" $R0
Sleep 200

${registry::RestoreKey} "${PORTABLEKEY1}" $R0
Sleep 200

SectionEnd



Section "LAUNCH"

ExecWait "$EXEDIR\Bin\${APPEXE}.exe"

SectionEnd



Section "UNMOUNT REGISTRY"

Delete "${PORTABLEKEY1}"

${registry::SaveKey} "${REGISTRYKEY1}" "${PORTABLEKEY1}" "/A=1" $R0
Sleep 200

${registry:😁eleteKey} "${REGISTRYKEY1}" $R0
Sleep 200

${registry::MoveKey} "${REGISTRYKEY1}-BackupBy${APPNOSPACE}Portable" "${REGISTRYKEY1}" $R0
Sleep 200

${registry::Unload}

SectionEnd

Nothing less, nothing more.

As you can see, the regkey is HKCU.
If I compile this code "as is" drag 'n drop works fine but the registry key is not update.
If I delete the row "RequestExecutionLevel user" the registry is updated, but I loose d 'n d.

How can I obtain both?
Is there an error in my code?

Thanks.
Anders#
"RequestExecutionLevel user" is guaranteed to be compatible with normal HKCU reads/writes.

There must be a problem with the way you are using the plug-in or you are looking at the wrong place in the registry (64-bit Windows?) with RegEdit.
Gluck#
"or you are looking at the wrong place in the registry (64-bit Windows?) with RegEdit".
The place where the key is copied is correct... (works fine!).

I'll try to replace NSIS and Registry.nsh with new one and let you know...
Anders#
You might have to be admin to execute RegRestoreKey, it really depends on how the plug-in does its registry handling.

I have said this many times before but here we go again:

Applications with built-in portable support is always better than writing a wrapper/launcher. Try to contact the original author and ask them to add a portable mode.
Gluck#
I have reduced the code (it's a test):


RequestExecutionLevel user

Section "Test"

!include "Registry.nsh"

${registry::RestoreKey} "$EXEDIR\User\Test.reg" $R0
Sleep 200

SectionEnd


This is the most minimalistic code that I could write.
Even in this situation, NSIS don't execute Regedit...

Is here an alternative to bypass Restorekey and obtain the same results?
Anders#
Write a custom plug-in that manually moves/copies a registry tree instead of using the part of the Windows registry API that requires admin (technically, RegRestoreKey requires you to be a backup operator user).

The calling process must have the SE_RESTORE_NAME and SE_BACKUP_NAME privileges on the computer in which the registry resides
Gluck#
I have resolved my troubles!

I have found the reasons of anomalous behaviour of my copy of NSIS.
I have downloaded the PortableApps version of NSIS portable from version 2.21 to the last.

These releases miss many files!!!

I have remembered that the compiler of PortableApps was able to edit registry, so I have used the NSIS program in PortableApps.comLauncher and now everything works fine.

As you can see, in the launcher and in the portable version the number of files and folders is different.

I wold advice you about this...

Thanks again.