Go Back   Winamp Forums > Developer Center > NSIS Discussion

Reply
Thread Tools Search this Thread Display Modes
Old 16th August 2011, 16:40   #1
Ron.Stordahl
Member
 
Join Date: Oct 2005
Location: Minnesota
Posts: 57
Is there a InstallDirRegKey analog for $APPDATA

I am updating an existing installer for Vista/Windows 7 which currently was designed for XP and below. For the installation directory I use this code:

PHP Code:
InstallDir "$PROGRAMFILES\${PRODUCT_NAME}"
InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" "" 
For the application data directory I use this:

PHP Code:
StrCpy $ApplicationDataPath $APPDATA${PRODUCT_NAME
Is there an analog to InstallDirRegKey for the application data path?
Ron.Stordahl is offline   Reply With Quote
Old 16th August 2011, 18:27   #2
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 2,776
No but you can make your own by using the registry functions in .oninit

IntOp $PostCount $PostCount + 1
Anders is online now   Reply With Quote
Old 16th August 2011, 20:14   #3
Ron.Stordahl
Member
 
Join Date: Oct 2005
Location: Minnesota
Posts: 57
Do you know where in the registry the information read by InstallDirRegKey is located? I have been unable to locate it. My installer is finding it, but where it is finding it I don't know. If it is any help I currently have these lines which might be a clue:

PHP Code:
!define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\BPQ32.exe"
.
InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" ""
.
WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$INSTDIR\BPQ32.exe" 
I remove the entry in the uninstall:

PHP Code:
DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}" 
Incidentlaly in Vista/Windows 7 I will be installing for the current user, so is it safe to assume that for those HKLM should be HKCU?
Ron.Stordahl is offline   Reply With Quote
Old 16th August 2011, 20:37   #4
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 2,776
Where? You are telling it where to look with InstallDirRegKey lol

IntOp $PostCount $PostCount + 1
Anders is online now   Reply With Quote
Old 16th August 2011, 21:02   #5
Ron.Stordahl
Member
 
Join Date: Oct 2005
Location: Minnesota
Posts: 57
Yes you are right of course! What is contained there in the registry is:

default REG_SZ C:\Program Files\BPQ32\BPQ32.exe

I see now that the command InstallDirRegKey will remove BPQ32.exe leaving just the path. Apparently it was pointless to include \BPQ32.exe in the WriteRegStr to start with.

Thanks again for your help, it has been very valuable for one just learning!
Ron.Stordahl is offline   Reply With Quote
Old 22nd August 2011, 14:16   #6
Ron.Stordahl
Member
 
Join Date: Oct 2005
Location: Minnesota
Posts: 57
This it would seem would be written in the registry at the HKLM root key, however what is actually happening is that for XP it is written at HKLM, but for Windows 7 it is written at HKCU.

PHP Code:
WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$INSTDIR\BPQ32.exe" 
Any idea of why this is happening?
Ron.Stordahl is offline   Reply With Quote
Old 22nd August 2011, 15:15   #7
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,840
Could be that win7 is "fixing" your installer because it's trying to write to HKLM without having admin access. Add "requestexecutionlevel admin" and use the userinfo plugin in .onInit to verify that you have admin (and throw an error and quit if you don't).
MSG is offline   Reply With Quote
Old 22nd August 2011, 17:19   #8
Ron.Stordahl
Member
 
Join Date: Oct 2005
Location: Minnesota
Posts: 57
I already had "requestexecutionlevel admin".

I added the following in .onInit:

PHP Code:
# call userInfo plugin to get user info.  The plugin puts the result in the stack
    
userInfo::getAccountType
    
# pop the result from the stack into $0
    
pop $
    
# compare the result with the string "Admin" to see if the user is admin.
    # If match, jump 3 lines down.
    
strCmp $"Admin" +
    
# if there is not a match, print message and return
    
messageBox MB_OK "not admin: $0"
    
return 
    
# otherwise, confirm and return
    
messageBox MB_OK "is admin" 
When running the created installer it reports "is admin".

So there is more to it apparently.
Ron.Stordahl is offline   Reply With Quote
Old 22nd August 2011, 18:15   #9
Ron.Stordahl
Member
 
Join Date: Oct 2005
Location: Minnesota
Posts: 57
That was kind of ugly...here is the actual code I am using to do the test:

PHP Code:
  userInfo::getAccountType    Check to see if we have gained administrative priv.   
  
pop $0
  
${If} $== "Admin"
    
messageBox MB_OK "is admin" 
  
${Else}
    
messageBox MB_OK "not admin: $0"
  
${Endif} 
The resulting messagebox displays "is admin"
Ron.Stordahl is offline   Reply With Quote
Old 22nd August 2011, 19:04   #10
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 2,776
Use Process Monitor to see what happens to the reg write...

IntOp $PostCount $PostCount + 1
Anders is online now   Reply With Quote
Old 22nd August 2011, 21:01   #11
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,840
Quote:
Originally Posted by Ron.Stordahl View Post
here is the actual code I am using to do the test:

PHP Code:
  userInfo::getAccountType    Check to see if we have gained administrative priv.   
  
pop $0
  
${If} $== "Admin"
    
messageBox MB_OK "is admin" 
  
${Else}
    
messageBox MB_OK "not admin: $0"
  
${Endif} 
Note: The above code is correct, but only for testing purposes. However, you need to use this code in your final installer as well, because 'requestexecutionlevel' does nothing if UAC is disabled, or on older OS versions... For that, you need to actually call the abort (or quit) command if the user isn't admin.
MSG is offline   Reply With Quote
Old 23rd August 2011, 19:20   #12
Ron.Stordahl
Member
 
Join Date: Oct 2005
Location: Minnesota
Posts: 57
I am using the following code to install a DLL:

PHP Code:
!insertmacro InstallLib DLL SHARED REBOOT_PROTECTED "..\BPQ32\Files\BPQ32.dll" $SYSDIRBPQ32.dll $SYSDIR 
Is it safe to say that the user who is running this installer will need Administrator Privileges to install that DLL? If so, then I will use the 'code' to test if the user has such privileges and if not, I will issue a message to that effect and abort.
Ron.Stordahl is offline   Reply With Quote
Old 23rd August 2011, 20:48   #13
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,840
Quote:
Originally Posted by Ron.Stordahl View Post
I am using the following code to install a DLL:

PHP Code:
!insertmacro InstallLib DLL SHARED REBOOT_PROTECTED "..\BPQ32\Files\BPQ32.dll" $SYSDIRBPQ32.dll $SYSDIR 
Is it safe to say that the user who is running this installer will need Administrator Privileges to install that DLL?
Yes. $SYSDIR is a protected directory, so you need admin privileges to write there.
MSG is offline   Reply With Quote
Old 24th August 2011, 14:10   #14
Ron.Stordahl
Member
 
Join Date: Oct 2005
Location: Minnesota
Posts: 57
How far back does that go? XP, W2K, or is this just Vista and later?
Ron.Stordahl is offline   Reply With Quote
Old 24th August 2011, 14:15   #15
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,840
All NT operating systems (NT, 2000, XP, Vista, etc..) have a protected $SYSDIR folder. The same applies to $WINDIR and $PROGRAMFILES, among others. (This means that if your default install directory is in program files and you don't check for admin access, your installer is kind of defective.)
MSG is offline   Reply With Quote
Reply
Go Back   Winamp Forums > Developer Center > NSIS Discussion

Tags
$appdata, installdirregkey

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