Old 8th December 2005, 19:07   #1
John P.
Member
 
Join Date: Jun 2004
Posts: 94
Installer won't read from HKCU ?

Hi - I've run into a little problem.

I have a few installers, that write a few things to the registry, both HKLM and HKCU.

Since some of my 'clients' don't always uninstall using the uninstaller, but just remove the program, the registry entries remain. So I have made a 'cleaner' file that searches the 'client's' registry for my strings, and deletes them if he/she wants to. The client can use that cleaner file if he/she hasn't properly uninstalled using my uninstaller.

However...

Some time ago, a client e-mailed me, saying he couldn't reinstall my installer because there were some old registry strings still present. It turned out that somehow (I have no idea how), the HKLM string had been deleted, but the HKCU string was still there.

So - I updated my 'cleaner' file so that it would look for the HKCU string as well(it didn't do that originally, because I didn't think it necessary). The cleaner file works in a way that if it detects the registry strings, a checkbox will appear on the install options page, and you can then check the checkbox and it will then remove the registry entries when you execute the cleaner file.

But - he wrote back again, saying that the cleaner file still didn't show the checkbox for that installer.

So I opened the script of the cleaner file, and looked through it. I then removed the HKLM search from it, leaving only the search for the HKCU strings.

Compiled, but as my client had experienced, the checkbox now didn't turn up (it did turn up when searching for the HKLM string).

What I find strange about that, is that on my computer, I am the only user, and I'm admin.

So why won't the installer read from HKCU? Is this a known thing?

I have checked and doublechecked the script, and the name of the string against the one directly from the registry, but I can't find anything wrong there.


My 'cleaner' file has lots of Sections that are UnSelected if the registry strings aren't found. In other words, as mentioned, if the string is found, the checkbox for that application will appear, and you can then remove that application's registry entries by clicking 'Next'.

Here's the code for the UnSelection part of the script (installer name is changed). I have only kep the HKCU part here:


code:

ReadRegStr $0 HKCU "Software\My_Installer.\Sections" "(Default)"
StrCmp $0 "" +2
Goto next
!insertmacro UnselectSection ${Sec00}
SectionSetText ${Sec00} ""

;some more strings are searched for here

next:



It finds the HKLM part(that isn't shown here) just fine, but not the HKCU part.

So again, my question is: Is there something wrong with my script anyway, or with the way I have written the name, or isn't it possible to read from HKCU at all?

I am right in thinking that the +2 only jumps over Goto next, right?
John P. is offline   Reply With Quote
Old 8th December 2005, 19:15   #2
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,449
to get the default value, use "" and not "(Default)"

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 8th December 2005, 19:31   #3
John P.
Member
 
Join Date: Jun 2004
Posts: 94
*Oops* -Is it really that easy?
OK, thanks - I'll try that!
John P. is offline   Reply With Quote
Old 8th December 2005, 19:34   #4
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
Perhaps a note should be made about this in the documentation for ReadRegStr.

-Stu
Afrow UK is offline   Reply With Quote
Old 8th December 2005, 19:37   #5
John P.
Member
 
Join Date: Jun 2004
Posts: 94
Hmm...

Changed the code to:

code:

ReadRegStr $0 HKCU "Software\My_Installer.\Sections" ""
StrCmp $0 "" +2
Goto next
!insertmacro UnselectSection ${Sec00}
SectionSetText ${Sec00} ""

next:



(in other words substituted "(Default)" with ""), and the checkbox still doesn't show up in the installer. It does show when using the same code, but for the HKLM string.

The HKLM string looks like this:

HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\My_Installer." "UninstallString"


If I change "Uninstallstring" with "" there, it doesn't find that either. But as it is, with "Uninstallstring" at the end, it finds it, and displays the checkbox.
John P. is offline   Reply With Quote
Old 8th December 2005, 19:51   #6
John P.
Member
 
Join Date: Jun 2004
Posts: 94
Ah...

For some reason, it works if I remove the 'Sections' thread part.

In other words, if I tell it to look for:

HKCU "Software\My_Installer." ""

it works.

Any idea why it doesn't when I make it look "through" the Sections thread?
John P. is offline   Reply With Quote
Old 9th December 2005, 15:16   #7
John P.
Member
 
Join Date: Jun 2004
Posts: 94
-I still need some help here.

It's as if it won't read the subkey. It will read/find the main key, but not the subkey.

This is a test script I'm using while I test this (installer name changed):

code:

Name "HKCU test"
OutFile "HKCU test.exe"

Section ""
ReadRegStr $0 HKCU "Software\My very nice installer.\Sections" ""
StrCmp $0 "" +3
MessageBox MB_OK "The string was found."
Goto End
MessageBox MB_OK "The string was not found."
End:
SectionEnd


;Actual registry string as exported from the registry:

;[HKEY_CURRENT_USER\Software\My very nice installer.\Sections]




It will only display the "The string was found." messagebox if I remove the \Sections part. But I need it to be included in the search. As it is (code above), it displays the "The string was not found." messagebox.

Is there any other way to write that subkey in there? I have tried to divide it into two, and having "Sections" after the name of the installer, but that didn't work either.
John P. is offline   Reply With Quote
Old 9th December 2005, 17:40   #8
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
What is the value of $0?
Are you checking if the key exists or the value?
If you're checking for the key, use IfErrors (with ClearErrors before using ReadRegStr).

-Stu
Afrow UK is offline   Reply With Quote
Old 9th December 2005, 18:29   #9
John P.
Member
 
Join Date: Jun 2004
Posts: 94
I was of the impression that the key would be put into the variable $0, and that I could then use the value to see if the string is there.

I have done that many times with other registry strings(HKLM mainly), and it has worked well.

If I for instance replace the registry string in the example above with another string (in HKLM), then the "The string was found." messagebox pops up. Which I interpret as 'string found'.

Since the example/testing script is so small, why would $0 be anything but the registry string? Nothing else is "going on" in the script. No other values/variables etc. I mean.
John P. is offline   Reply With Quote
Old 9th December 2005, 19:07   #10
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
The only reason it could skip the code is if the value of $0 is "", meaning that you have no value set in the default "" key name.

If there is a value present, then the only thing that I can guess which may cause a problem is that you have a full stop on the end of one of the registry folder names. Perhaps removing that may fix the problem, unless that doesn't exist in your main script.

-Stu
Afrow UK is offline   Reply With Quote
Old 9th December 2005, 19:15   #11
John P.
Member
 
Join Date: Jun 2004
Posts: 94
Thanks for the help. I suddenly understand a bit more of how it all works now.

It turned out that I am trying to read a registry key that has no value ( (value not set) ), so of course there's nothing returned.

I think I can work it out from here.
John P. 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