- NSIS Discussion
- Get a path from registry, if not found send error message
Archive: Get a path from registry, if not found send error message
Reenan
10th January 2010 12:10 UTC
Get a path from registry, if not found send error message
Yeah, it's me again. I've searched for this, but nothing found.
I want that my installer search for a path in registry. BUT, if it don't find anything, I want that the installer send a message and SKIP the section that need the path.
Something like: get a path from an app. If it don't find the path, send a message saying 'install app needed first, then try to install the plugin ('or whatever') again' and go to next section.
Right now, I have this:
MessageBox MB_OK "$(MessageWinamp)"
ReadRegStr $0 HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\winamp.exe" "Path"
DetailPrint "Winamp is installed at: $0"
SetDetailsPrint textonly
DetailPrint "$(InstallWinamp)"
SetDetailsPrint listonly
Sleep 1000
SetOutPath "$0\Plugins"
File "gen_CADStarter.Plugin.dll"
File "CADStarter.dll"
How I can implement it?
jpderuiter
10th January 2010 12:23 UTC
From the NSIS manual:
The error flag will be set and $x will be set to an empty string ("") if the string is not present. If the value is present, but is of type REG_DWORD, it will be read and converted to a string and the error flag will be set.
So you should check if the error flag is set (with IfErrors) and if $0 =="".
Joel
10th January 2010 14:24 UTC
Hi Reenan:
If you are looking for Winamp install path, I recommend that you use the "uninstall" entry from the registry (where add and remove programs are placed), since is been used since Winamp 2.x series or older.
Reenan
10th January 2010 15:33 UTC
Originally posted by jpderuiter
From the NSIS manual:So you should check if the error flag is set (with IfErrors) and if $0 =="".
I don't know how to do this :/ I've looked a bit into the manual, but it seems to confuse to me! (Remember, I'm brazilian, so lots of things written in english can look tough to me)
can you give me a little explanation on it?
About yout tip, Joel, I was using Winamp key present in Software root first, then someone told me to use that one. For God's sake, what key is easier to use?
jpderuiter
10th January 2010 17:53 UTC
ReadRegStr $0 HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\winamp.exe" "Path"
IfErrors 0 RegOK
StrCmp $0 "" 0 RegOK
DetailPrint "Error reading registry"
Goto End
RegOK:
DetailPrint "Registry value: $0"
End:
MSG
11th January 2010 08:51 UTC
Actually there should be a
ClearErrors
line just before that code...
Reenan
11th January 2010 10:53 UTC
Before the 'End:' one?
MSG
11th January 2010 11:28 UTC
No, before the code. Before all of the code. Like this:
ClearErrors
ReadRegStr $0 HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\winamp.exe" "Path"
IfErrors 0 RegOK
StrCmp $0 "" 0 RegOK
DetailPrint "Error reading registry"
Goto End
RegOK:
DetailPrint "Registry value: $0"
End:
Note: I
really recommend using LogicLib. It'll greatly increase the readability of your code:
ClearErrors
ReadRegStr $0 HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\winamp.exe" "Path"
${If} ${Errors}
${OrIf} $0 == ""
DetailPrint "Error reading registry"
${Else}
DetailPrint "Registry value: $0"
${EndIf}
Edit: Come to think of it, in this case you don't need to use the Error flag at all. As long as $0 is empty we're in trouble, regardless of the actual error flag.
ReadRegStr $0 HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\winamp.exe" "Path"
${If} $0 == ""
DetailPrint "Error reading registry"
${Else}
DetailPrint "Registry value: $0"
${EndIf}
Joel
11th January 2010 14:34 UTC
Originally posted by Reenan
I don't know how to do this :/ I've looked a bit into the manual, but it seems to confuse to me! (Remember, I'm brazilian, so lots of things written in english can look tough to me)
can you give me a little explanation on it?
About yout tip, Joel, I was using Winamp key present in Software root first, then someone told me to use that one. For God's sake, what key is easier to use?
Are you targeting modern Winamp versions?
Reenan
11th January 2010 19:58 UTC
Originally posted by Joel
Are you targeting modern Winamp versions?
Well, I'm writing a installer for the CAD Plugin for winamp. CAD site and even plugin download don't seem to say for which version it its. This way, I'll consider it to modern Winamp.
EDIT:
One more thing (I don't want to create a new topic again). There is some way to use the entire header as image?
ANOTHER EDIT (to don't create another topic):
How can I do a file check during uninstall?
- Check if a file exists. If exist, do something. If not, same as my first problem: send a message and skip it.