Go Back   Winamp Forums > Developer Center > NSIS Discussion

Reply
Thread Tools Search this Thread Display Modes
Old 14th February 2011, 13:16   #1
Salinn
Junior Member
 
Join Date: Sep 2008
Posts: 16
Writing and reading from the same reg key

Hello,

I haven't found a thread that describes the same issue that I'm having, therefor I will try to detail my problem as much as I can.

I've created an installer which will read a certain registry key and, after "parsing" it with StrCpy, it will write it in another registry key. When the installer ends (.onGUIEnd) that new created registry key will be deleted; so it will act as a temporary registry key.

The problem that I've encounter is that the installer doesn't read the new written registry key.

The following code will write the temporary registry key without any problem.

code:
Var $one

Function test
ReadRegStr $one HKLM SOFTWARE\Program\Nice InstallPath
!define something $one\install_here
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Stuff TMP" "TMPPath" "${something}"
FunctionEnd



Now, if I want to get that key and make it the installation directory, it won't be able to read it.

code:
InstallDirRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Stuff TMP" "TMPPath"


The above code-line will only work if the installer is reopened and the temporarily registry key is not deleted upon closing.

My question is: How can I write and read the same registry key in the same installation process?

Looking forward to your reply.
Salinn is offline   Reply With Quote
Old 14th February 2011, 14:35   #2
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,841
As far as I know, the InstallDirRegKey is read before the installer even starts. It's like an automatic "ReadRegStr $INSTDIR Hive Path Key" command in .onInit. What you'll need to do is do it manually, after the key is created. (But seriously, why on earth would you want to do that? Just StrCpy $INSTDIR "${something}" would suffice...)
MSG is offline   Reply With Quote
Old 14th February 2011, 15:17   #3
Salinn
Junior Member
 
Join Date: Sep 2008
Posts: 16
Hello,

Thank you for the fast reply.

At first I tried that but unfortunately, by the time I ended up in the Directory Page, the $INSTDIR was empty. I tried using global variables and even !define to get that key stored after ReadRegStr but every time the Function .... FunctionEnd passed that variable became "unset"
Salinn is offline   Reply With Quote
Old 15th February 2011, 05:49   #4
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,841
I'm pretty sure there's absolutely no problem with reading a regstr you created in earlier. If your $INSTDIR is empty, there's a problem in your script. Use MessageBox etc to find the problem (specifically, check the location of the regstr you're telling it to read/write).

Also: ALL variables in NSIS are global. There are no local variables.
MSG is offline   Reply With Quote
Old 15th February 2011, 07:01   #5
jiake
Senior Member
 
jiake's Avatar
 
Join Date: Oct 2007
Location: Xi'an, China
Posts: 194
!define is a compiling command, whether use it or not is the same.
You need to find out the origin of your problem.

An NSIS fan from China, my name is Jia Ke (pinyin).
Email: jiake@vip.qq.com
Messenger: jiake@live.in
QQ (Chinese IM): 550771955
jiake is online now   Reply With Quote
Old 15th February 2011, 07:17   #6
Salinn
Junior Member
 
Join Date: Sep 2008
Posts: 16
Hello,

Thank you for the replies.

I've tried creating a simple example to show the issue I'm having. Testing it will have the same result.

code:
!include MUI2.nsh

OutFile "Test.exe"

!define MUI_PAGE_CUSTOMFUNCTION_SHOW test
!insertmacro MUI_PAGE_WELCOME
!define MUI_PAGE_CUSTOMFUNCTION_SHOW CustomShow
!insertmacro MUI_PAGE_DIRECTORY
InstallDirRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Stuff TMP" "TMPPath"

Var path
Var trim_path

Function test
ReadRegStr $path HKLM SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winamp DisplayIcon
StrCpy $trim_path $path 23
; MessageBox MB_OK $trim_path
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Stuff TMP" "TMPPath" "$trim_path"
FunctionEnd

Function CustomShow
MessageBox MB_OK $trim_path
FunctionEnd

Function .onGUIEnd
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Stuff TMP"
FunctionEnd

Section .onInit
SectionEnd



When the installer is open, the key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Stuff TMP\TMPPath" exists but, regardless where I put the InstallDirRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Stuff TMP" "TMPPath" line, it won't fill in the path.

PS: The messagebox shows the path correctly the problem is setting the InstallDir with that variable.
Salinn is offline   Reply With Quote
Old 15th February 2011, 08:16   #7
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,841
Like I said, you'll need to ReadRegStr MANUALLY. Don't use InstallDirRegKey.
MSG is offline   Reply With Quote
Old 15th February 2011, 08:24   #8
Salinn
Junior Member
 
Join Date: Sep 2008
Posts: 16
Hello,

Ok, I changed it to ReadRegStr when the Directory Page is shown but nothing seems to be changed.

code:
!include MUI2.nsh

OutFile "Test.exe"

!define MUI_PAGE_CUSTOMFUNCTION_SHOW test
!insertmacro MUI_PAGE_WELCOME
!define MUI_PAGE_CUSTOMFUNCTION_SHOW CustomShow
!insertmacro MUI_PAGE_DIRECTORY
;InstallDirRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Stuff TMP" "TMPPath"

Var path
Var trim_path

Function test
ReadRegStr $path HKLM SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winamp DisplayIcon
StrCpy $trim_path $path 23
; MessageBox MB_OK $trim_path
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Stuff TMP" "TMPPath" "$trim_path"
FunctionEnd

Function CustomShow
ReadRegStr $INSTDIR HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Stuff TMP" "TMPPath"
MessageBox MB_OK $INSTDIR
FunctionEnd

Function .onGUIEnd
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Stuff TMP"
FunctionEnd

Section .onInit
SectionEnd

Salinn is offline   Reply With Quote
Old 15th February 2011, 09:50   #9
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,841
First of all, you DO have administrator access when you run this test installer, right? >__>

Other tips:
- Reading the written regstring is still entirely pointless. Just use the variable containing the path directly!
- $trim_path is unneeded, just use StrCpy $path $path 23. Saves one variable.
- Why trim the first 23 characters? If I installed winamp to c:\foobar, the trim result will be entirely different from when I installed to c:\Program Files (x86)\Multimedia\z0mglongpath\winamp...
MSG is offline   Reply With Quote
Old 15th February 2011, 10:17   #10
Salinn
Junior Member
 
Join Date: Sep 2008
Posts: 16
Hello,

I will reply to your message in the same order:

0. Yes, I'm running as Administrator.

1. I've tried that as well (at the first time I've created the script) but it didn't worked so I guessed that I need to save it somewhere and read it back.

2. Point taken.

3. I've trimmed that because in the registry, under HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winamp\DisplayIcon you will find something like "C:\Program Files\Winamp\winamp.exe,0". I've trim it to get a folder of an already installed application.

After getting that path I could easily modify it according to my needs adding somethig like "$already_installed_application\plugins" folder that can't be found in the registry or anywhere else.

I tried now something, based on your idea and I finally managed to get it to work. It seems that I need to set the $INSTDIR before the CUSTOMFUNCTION_SHOW. I guess my previous testing was made using it in that function.

Thank you for all your help and for bearing with me.
Salinn is offline   Reply With Quote
Old 15th February 2011, 10:33   #11
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Birmingham, England
Posts: 8,202
Why would you trim to 23 characters? That will only work when the path starts with C:\Program Files\Winamp in which case, what is the point of reading the path in the first place?

This is what you want:
code:
!include FileFunc.nsh
Function .onInit
ReadRegStr $R0 HKLM SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winamp DisplayIcon
${GetParent} $R0 $INSTDIR
FunctionEnd

Stu

Need an installer? http://www.afrowsoft.co.uk
Afrow UK is offline   Reply With Quote
Old 15th February 2011, 11:26   #12
Salinn
Junior Member
 
Join Date: Sep 2008
Posts: 16
Hello,

Thank you for the idea, Stu.
Salinn is offline   Reply With Quote
Reply
Go Back   Winamp 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