Okay...
I'm making a launcher for an app that happens to be using 4 different registry keys, and all of them are essential for the program to run. I've been looking at the NSIS script for 7-zip, but it only needs one key. My question is: How do I arrange the script when it is using more than one key? Here is the section I've been working with:
RegistryBackup:
StrCmp $SECONDARYLAUNCH "true" LaunchAndExit
;=== Backup the registry
${registry::KeyExists} "HKEY_CURRENT_USER\Software\7-zip-BackupBy7-ZipPortable" $R0
StrCmp $R0 "0" RestoreTheKey
${registry::KeyExists} "HKEY_CURRENT_USER\Software\7-zip" $R0
StrCmp $R0 "-1" RestoreTheKey
${registry::MoveKey} "HKEY_CURRENT_USER\Software\7-zip" "HKEY_CURRENT_USER\Software\7-zip-BackupBy7-ZipPortable" $R0
Sleep 100
RestoreTheKey:
IfFileExists "$SETTINGSDIRECTORY\7zip_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\7zip_portable.reg" $R0
StrCmp $R0 '0' LaunchNow ;successfully restored key
StrCpy $FAILEDTORESTOREKEY "true"
LaunchNow:
Sleep 100
ExecWait $EXECSTRING
I need to duplicate this for the other keys. Should I just copy it 4 times, or should it be merged together? Can anyone help?
Thanks.
All you do is make doubles of the same code, if you told me what your registry keys were i could write it 4 you and give you the code. But make sure it is just the main registry key, not all the sub keys within the main one, like the main one from one of my launchers is HKEY_CURRENT_USER\Software\Piriform while it has a sub key that is HKEY_CURRENT_USER\Software\Piriform\Recuva with all this other stuff.
An eye for an eye makes the whole world blind.
Mahatma Gandhi,
Indian political and spiritual leader (1869 - 1948)
k the launcher i made recently used to main registry keys, HKEY_LOCAL_MACHINE\SOFTWARE\Piriform and HKEY_CURRENT_USER\Software\Piriform, so here is how i added them, please look closley at what was done, cause after you look at this you should be able to do yours, just yours has 2 more keys than mine did. its a bit long so here it is.....oh yeah i also used 7zip source code for the launcher I made.....
RegistryBackup: StrCmp $SECONDARYLAUNCH "true" LaunchAndExit ;=== Backup the registry ${registry::KeyExists} "HKEY_LOCAL_MACHINE\SOFTWARE\Piriform" $R0 StrCmp $R0 "0" RestoreTheKey ${registry::KeyExists} "HKEY_CURRENT_USER\Software\Piriform" $R0 StrCmp $R0 "0" RestoreTheKey ${registry::KeyExists} "HKEY_LOCAL_MACHINE\SOFTWARE\Piriform" $R0 StrCmp $R0 "-1" RestoreTheKey ${registry::KeyExists} "HKEY_CURRENT_USER\Software\Piriform" $R0 StrCmp $R0 "-1" RestoreTheKey ${registry::MoveKey} "HKEY_LOCAL_MACHINE\SOFTWARE\Piriform" "HKEY_LOCAL_MACHINE\SOFTWARE\Piriform" $R0 ${registry::MoveKey} "HKEY_CURRENT_USER\Software\Piriform" "HKEY_CURRENT_USER\Software\Piriform" $R0 Sleep 100 RestoreTheKey: IfFileExists "$SETTINGSDIRECTORY\Defraggler.reg" "" LaunchNow IfFileExists "$WINDIR\system32\reg.exe" "" RestoreTheKey9x nsExec::ExecToStack `"$WINDIR\system32\reg.exe" import "$SETTINGSDIRECTORY\Defraggler.reg"` Pop $R0 StrCmp $R0 '0' LaunchNow ;successfully restored key RestoreTheKey9x: ${registry::RestoreKey} "$SETTINGSDIRECTORY\Defraggler.reg" $R0 StrCmp $R0 '0' LaunchNow ;successfully restored key StrCpy $FAILEDTORESTOREKEY "true"An eye for an eye makes the whole world blind.
Mahatma Gandhi,
Indian political and spiritual leader (1869 - 1948)
Thanks man, I'll give you some credit in the launcher when I finish it.
It may be better to keep them each seperated, instead of interlocked like that, for example
StrCmp $SECONDARYLAUNCH "true" LaunchAndExit ;=== Backup the registry RegBackup1: ${registry::KeyExists} "HKEY_CURRENT_USER\Software\Piriform" $R0 StrCmp $R0 "0" RegBackup2 ${registry::KeyExists} "HKEY_CURRENT_USER\Software\Piriform" $R0 StrCmp $R0 "-1" RegBackup2 ${registry::MoveKey} "HKEY_CURRENT_USER\Software\Piriform" "HKEY_CURRENT_USER\Software\Piriform" $R0 Sleep 100 RegBackup2: ${registry::KeyExists} "HKEY_LOCAL_MACHINE\SOFTWARE\Piriform" $R0 StrCmp $R0 "0" RestoreTheKey ${registry::KeyExists} "HKEY_LOCAL_MACHINE\SOFTWARE\Piriform" $R0 StrCmp $R0 "-1" RestoreTheKey ${registry::MoveKey} "HKEY_LOCAL_MACHINE\SOFTWARE\Piriform" "HKEY_LOCAL_MACHINE\SOFTWARE\Piriform" $R0 Sleep 100This way, if one set of keys fails, the other can still be processed. The the setup listed above, if the very first condition isn't passed, it jumps right to RestoreTheKey, skipping all other reg keys.
The developer formerly known as ZGitRDun8705
Dont forget to do this afterwards, to make sure it works properly. Take your time as it is easy to forget and make mistakes.Also make sure on SetOriginalKeyBack: you add all your keys to delete and Keyexists or they wont be removed.
LaunchNow: Sleep 100 ExecWait $EXECSTRING CheckRunning: Sleep 1000 FindProcDLL::FindProc "${DEFAULTEXE}" StrCmp $R0 "1" CheckRunning StrCmp $FAILEDTORESTOREKEY "true" SetOriginalKeyBack ${registry::SaveKey} "HKEY_CURRENT_USER\Software\Piriform" "$SETTINGSDIRECTORY\Defraggler.reg" "" $0 ${registry::SaveKey} "HKEY_LOCAL_MACHINE\SOFTWARE\Piriform" "$SETTINGSDIRECTORY\Defraggler.reg" "" $0 Sleep 100 SetOriginalKeyBack: ${registry::DeleteKey} "HKEY_CURRENT_USER\Software\Piriform" $R0 ${registry::DeleteKey} "HKEY_LOCAL_MACHINE\SOFTWARE\Piriform" $R0 Sleep 100 ${registry::KeyExists} "HKEY_CURRENT_USER\Software\Piriform" $R0 StrCmp $R0 "-1" TheEnd ${registry::KeyExists} "HKEY_LOCAL_MACHINE\SOFTWARE\Piriform" $R0 StrCmp $R0 "-1" TheEnd ${registry::MoveKey} "HKEY_CURRENT_USER\Software\Piriform" "HKEY_CURRENT_USER\Software\Piriform" $R0 ${registry::MoveKey} "HKEY_LOCAL_MACHINE\SOFTWARE\Piriform" "HKEY_LOCAL_MACHINE\SOFTWARE\Piriform" $R0 Sleep 100 Goto TheEndAn eye for an eye makes the whole world blind.
Mahatma Gandhi,
Indian political and spiritual leader (1869 - 1948)
HKLM is a special case. Only an admin account can write to it. Check out the Eraser Portable launcher for example code on handling both HKCU and HKLM and checking for account rights.
Sometimes, the impossible can become possible, if you're awesome!
I'll check out the source for eraser portable asap.
Thanks.
I just used what Rab040ma gave me. A macro to check if admin, and if it is, it'll do those reg keys.
Insert original signature here with Greasemonkey Script.