Old 3rd September 2011, 22:58   #1
SteveRussell
Senior Member
 
Join Date: Mar 2006
Location: United States
Posts: 109
Need to store text files in AppData folder

Now that I am in Windows 7, I suddenly find that simple text files that my app updates per user are denied access. Until now, I have kept these profiles in a subfolder of my install directory.

I am wondering if I could get a bit of direction on how to use NSIS to find the right appdata folder and place some files in that location during installation. Of course, the folder name varies, such as 'Application Data' in XP and 'AppData' in Windows 7. I am thinking and hoping that this move will eliminate access problems.
SteveRussell is offline   Reply With Quote
Old 4th September 2011, 04:48   #2
msroboto
Junior Member
 
Join Date: Sep 2006
Posts: 47
Look up $APPDATA in the wiki.
I think that's what you want. There is a warning about how the SetShellVarContext is set.
msroboto is offline   Reply With Quote
Old 4th September 2011, 05:48   #3
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,892
It's all in the manual.

http://nsis.sourceforge.net/Docs/Chapter4.html#4.2.3
MSG is offline   Reply With Quote
Old 4th September 2011, 07:45   #4
SteveRussell
Senior Member
 
Join Date: Mar 2006
Location: United States
Posts: 109
Thank you, gentlemen. I did discover $APPDATA after posting, but this is a new concept for me.

I am wondering: When might "All Users" be chosen over "Current user"?
SteveRussell is offline   Reply With Quote
Old 5th September 2011, 09:48   #5
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,442
Quote:
Originally Posted by SteveRussell View Post
I am wondering: When might "All Users" be chosen over "Current user"?
I you have things that are shared with all users of your program

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 4th September 2011, 16:43   #6
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,892
If you enforce admin access for your installer (for example because you need to write to a protected directory such as $SYSTEM or $PROGRAMFILES), you must install for all users. In this case, you must use the HKLM registry hive for all registry stuff.

If you do not do anything that requires admin access, you can do one of two things:
1) Force admin-only installation anyway. This means installing for all users and using HKLM (see above).
2) Allow user-level installation. This means NOT asking for admin access, NOT writing to any protected folders, only installing for the current user, and using the HKCU registry hive instead of HKLM.

This is how windows is designed to operate, so this is how you're supposed to do it.
MSG is offline   Reply With Quote
Old 5th September 2011, 13:45   #7
SteveRussell
Senior Member
 
Join Date: Mar 2006
Location: United States
Posts: 109
Quote:
Originally Posted by MSG View Post
If you enforce admin access for your installer (for example because you need to write to a protected directory such as $SYSTEM or $PROGRAMFILES), you must install for all users.
I definitely do write to program files. But I thought that it was no longer possible to enforce admin access with RequestExecutionLevel.
SteveRussell is offline   Reply With Quote
Old 5th September 2011, 14:48   #8
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
You need RequestExecutionLevel admin but you still need to check the user is an administrator in .onInit and abort if they are not.

Stu
Afrow UK is offline   Reply With Quote
Old 5th September 2011, 15:03   #9
SteveRussell
Senior Member
 
Join Date: Mar 2006
Location: United States
Posts: 109
Quote:
Originally Posted by Afrow UK View Post
You need RequestExecutionLevel admin but you still need to check the user is an administrator in .onInit and abort if they are not.

Stu
I would love to see an example of checking the user. Haven't found one yet.
SteveRussell is offline   Reply With Quote
Old 5th September 2011, 15:07   #10
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,892
requestexecutionlevel doesn't do anything in WinXP, or in Win7 if UAC is turned off. So use both:

requestexecutionlevel admin

function .onInit
userInfo::getAccountType
pop $0
${If} $0 != "Admin"
messageBox MB_OK "Requires admin"
quit
${EndIf}
functionend

(and same for un.onInit!)
MSG is offline   Reply With Quote
Old 5th September 2011, 15:57   #11
SteveRussell
Senior Member
 
Join Date: Mar 2006
Location: United States
Posts: 109
(Ignore this post. I had inserted code before includes.):

Thank you. I'm getting an error:

Function: ".onInit"
File: "UserInfo.dll"->"$PLUGINSDIR\UserInfo.dll" [compress] 1336/4096 bytes
Plugin Command: GetAccountType
Pop: $0
Invalid command: ${If}

------

Function .onInit
UserInfo::GetAccountType
Pop $0
${If} $0 != "Admin"
MessageBox MB_OK "Your system requires administrative permissions in order to install this software."
Quit
${EndIf}
FunctionEnd

Last edited by SteveRussell; 5th September 2011 at 16:02. Reason: Realized code block had been inserted before includes
SteveRussell is offline   Reply With Quote
Old 5th September 2011, 18:49   #12
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,442
!include LogicLib.nsh

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 7th September 2011, 09:58   #13
SteveRussell
Senior Member
 
Join Date: Mar 2006
Location: United States
Posts: 109
Should I remove related folders and data files from the appdata folder when uninstalling?
SteveRussell is offline   Reply With Quote
Old 7th September 2011, 13:55   #14
msroboto
Junior Member
 
Join Date: Sep 2006
Posts: 47
Depends what it is. If you uninstall word do you expect the .doc files to be deleted.
I don't know if that analogy works in your case.
msroboto is offline   Reply With Quote
Old 7th September 2011, 15:15   #15
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,892
You should delete everything you don't want to keep. As simple as that.
MSG is offline   Reply With Quote
Old 8th September 2011, 22:57   #16
SteveRussell
Senior Member
 
Join Date: Mar 2006
Location: United States
Posts: 109
I kind of like the doc comparison. My tiny data files are profiles that record user progress, otherwise meaningless when the application is uninstalled. But they could remain for re-installation.

I have never before dealt programmatically with the appdata file structure, so never had to think about some of these ramifications. I treat the register very carefully, leaving it clean at uninstall. Now I am wondering about the neighborhood rules - Is it considered sloppy to allow some files to remain in appdata when the program is removed?
SteveRussell is offline   Reply With Quote
Old 12th September 2011, 11:27   #17
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,892
Quote:
Originally Posted by SteveRussell View Post
Is it considered sloppy to allow some files to remain in appdata when the program is removed?
That entirely depends on your definition. "Uninstallation" implies you undo the installation, but you can define "installation" as that which the installer created (so, only the original application), or you can define it as everything that comprises and belongs to the installed application (so, both the app and its settings etc).

Note that it may also depend on the size and number of files you're leaving behind. What most uninstallers do is add a checkbox or messagebox option to delete saves/settings along with the application.
MSG is offline   Reply With Quote
Old 12th September 2011, 12:04   #18
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
You should ask the user if they wish the files to be deleted. You can either use a simple MessageBox, and an uninstall component (i.e. another un. Section) or add a custom page with a check-box on it.

Stu
Afrow UK is offline   Reply With Quote
Old 13th September 2011, 00:56   #19
SteveRussell
Senior Member
 
Join Date: Mar 2006
Location: United States
Posts: 109
Yes, I need to give the user the choice to delete or keep the associated files. Thank you all again for your thoughts, which have clarified mine. I greatly appreciate your advice and direction.
SteveRussell is offline   Reply With Quote
Old 13th September 2011, 22:13   #20
SteveRussell
Senior Member
 
Join Date: Mar 2006
Location: United States
Posts: 109
Quote:
Originally Posted by Afrow UK View Post
You can either use a simple MessageBox, and an uninstall component (i.e. another un. Section)....

Stu
Section, or Function?
SteveRussell is offline   Reply With Quote
Old 14th September 2011, 10:25   #21
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
You can have multiple uninstall sections along with an uninstall components page (read the docs).

Stu
Afrow UK is offline   Reply With Quote
Old 18th September 2011, 10:02   #22
SteveRussell
Senior Member
 
Join Date: Mar 2006
Location: United States
Posts: 109
OK, I have created un.CleanUp_Profiles as an additional Section.

Section un.CleanUp_Profiles
MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Do you want to delete all Sign In id's associated with $(^Name)?" IDYES true IDNO false
true:
Delete "$APPDATA\${PRODUCT_FAMILY}\pf\*_scii.txtt"
Goto next
false:
Goto next
next:
SectionEnd

I was already conditionally deleting other files and folders in Section Uninstall, depending on whether or not other similar products have been installed in the same directory.

I don't see the docs telling me what should go inside the main section and what should not.
SteveRussell is offline   Reply With Quote
Old 19th September 2011, 04:45   #23
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,892
For NSIS it doesn't matter in which section you put it. That's entirely up to you. If you want to make it an optional section, obviously all the optional files should be deleted in that section, not in another.
MSG 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