Archive: Get a path from registry, if not found send error message


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?

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 =="".

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.


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?

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:

Actually there should be a

ClearErrors
line just before that code...

Before the 'End:' one?


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}

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?

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.