You are here

NSIS registry help

3 posts / 0 new
Last post
ToJa92
Offline
Last seen: 11 years 4 months ago
Joined: 2008-05-27 15:16
NSIS registry help

(I hope I got this in the right place)

Hello, I'm creating my own portable version of RollerCoaster Tycoon 2(hence I don't follow official specs or anything) and I've run into a problem. I got this piece of code:


${registry::MoveKey} "HKEY_LOCAL_MACHINE\SOFTWARE\Infogrames\" "HKEY_LOCAL_MACHINE\SOFTWARE\Infogrames-backup\" $R0
Sleep 100

Which works as expected. However, the opposite does nothing:


${registry::MoveKey} "HKEY_LOCAL_MACHINE\SOFTWARE\Infogrames-backup\" "HKEY_LOCAL_MACHINE\SOFTWARE\Infogrames\" $R0
Sleep 100

I remove HKEY_LOCAL_MACHINE\SOFTWARE\Infogrames\ by restoring a .reg file containing:

Windows Registry Editor Version 5.00

[-HKEY_LOCAL_MACHINE\SOFTWARE\Infogrames]

before trying to rename the backup key back. The backup simply disappears instead of being renamed.
Anyone know of a solution?
I'm running Windows 7 Home Premium x86 right now, if that matters.
And I'm not very skilled with NSIS, by the way.

Mark Sikkema
Offline
Last seen: 13 years 3 months ago
Developer
Joined: 2009-07-20 14:55
I've tested your code and it

I've tested your code and it does work on my side, stangely enough ! You could do away with the last back-slash, thought.

Anyhow, in the portableApps launchers we use a slightly extended bit of code, just to play safe.
Before to start your app:

${registry::KeyExists} "HKEY_CURRENT_USER\Software\Infogrames-Backup" $R0
StrCmp $R0 "0" RestoreTheKey
${registry::KeyExists} "HKEY_CURRENT_USER\Software\Infogrames" $R0
StrCmp $R0 "-1" RestoreTheKey
${registry::MoveKey} "HKEY_CURRENT_USER\Software\Infogrames" "HKEY_CURRENT_USER\Software\Infogrames-Backup" $R0
Sleep 100

RestoreTheKey:
IfFileExists "$SETTINGSDIRECTORY\RollerCoaster_portable.reg" "" LaunchNow
IfFileExists "$WINDIR\system32\reg.exe" "" RestoreTheKey9x
nsExec::ExecToStack `"$WINDIR\system32\reg.exe" import "$SETTINGSDIRECTORY\7zip_portable.reg"`
Pop $R0
StrCmp $R0 '0' LaunchNow ;successfully restored key
RestoreTheKey9x:
${registry::RestoreKey} "$SETTINGSDIRECTORY\RollerCoaster_portable.reg" $R0
StrCmp $R0 '0' LaunchNow ;successfully restored key

On exit:

${registry::SaveKey} "HKEY_CURRENT_USER\Software\Infogrames" "$SETTINGSDIRECTORY\RollerCoaster_portable.reg" "" $0
Sleep 100
${registry::DeleteKey} "HKEY_CURRENT_USER\Software\Infogrames" $R0
Sleep 100
${registry::KeyExists} "HKEY_CURRENT_USER\Software\Infogrames-Backup" $R0
StrCmp $R0 "-1" TheEnd
${registry::MoveKey} "HKEY_CURRENT_USER\Software\Infogrames-Backup" "HKEY_CURRENT_USER\Software\Infogrames" $R0
Sleep 100

Have a look in the source of the PortableApps launchers! Like NsisPortable, as a simple example !

Formerly Gringoloco
Windows XP Pro sp3 x32

ToJa92
Offline
Last seen: 11 years 4 months ago
Joined: 2008-05-27 15:16
There's no settings that

There's no settings that change anyway in the registry so saving it for the next run isn't needed. Also, you're correct that it works. It probably something else removing the keys, I'll have to check further. Thank you anyway Smile

EDIT: Scratch everything, seems to be a problem with the EXE file I was launching(not a official one). Also I'm not sure what settings are stored so the ability to save settings might come in handy, thanks again Biggrin

EDIT#2: Now everything's working as it should. I just increased the Sleep to 1000, and now I'm saving the local data before importing the data that makes it work.

Log in or register to post comments