Old 13th January 2019, 12:02   #1
Gluck
Senior Member
 
Join Date: Apr 2018
Posts: 103
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.
Gluck is offline   Reply With Quote
Old 13th January 2019, 14:06   #2
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,014
"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.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 13th January 2019, 15:23   #3
Gluck
Senior Member
 
Join Date: Apr 2018
Posts: 103
"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...
Gluck is offline   Reply With Quote
Old 13th January 2019, 17:00   #4
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,014
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.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 17th January 2019, 13:49   #5
Gluck
Senior Member
 
Join Date: Apr 2018
Posts: 103
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?
Gluck is offline   Reply With Quote
Old 17th January 2019, 13:57   #6
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,014
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).

Quote:
The calling process must have the SE_RESTORE_NAME and SE_BACKUP_NAME privileges on the computer in which the registry resides

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 19th January 2019, 19:34   #7
Gluck
Senior Member
 
Join Date: Apr 2018
Posts: 103
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.
Gluck is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump