|
|
|
|
#1 |
|
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. |
|
|
|
|
|
#2 |
|
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. |
|
|
|
|
|
#3 |
|
Major Dude
Join Date: Oct 2006
Posts: 1,892
|
|
|
|
|
|
|
#4 |
|
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"? |
|
|
|
|
|
#5 |
|
Moderator
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,442
|
I you have things that are shared with all users of your program
IntOp $PostCount $PostCount + 1 |
|
|
|
|
|
#6 |
|
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. |
|
|
|
|
|
#7 |
|
Senior Member
Join Date: Mar 2006
Location: United States
Posts: 109
|
I definitely do write to program files. But I thought that it was no longer possible to enforce admin access with RequestExecutionLevel.
|
|
|
|
|
|
#8 |
|
Moderator
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 |
|
|
|
|
|
#9 |
|
Senior Member
Join Date: Mar 2006
Location: United States
Posts: 109
|
|
|
|
|
|
|
#10 |
|
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!) |
|
|
|
|
|
#11 |
|
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 |
|
|
|
|
|
#12 |
|
Moderator
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,442
|
!include LogicLib.nsh
IntOp $PostCount $PostCount + 1 |
|
|
|
|
|
#13 |
|
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?
|
|
|
|
|
|
#14 |
|
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. |
|
|
|
|
|
#15 |
|
Major Dude
Join Date: Oct 2006
Posts: 1,892
|
You should delete everything you don't want to keep. As simple as that.
|
|
|
|
|
|
#16 |
|
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? |
|
|
|
|
|
#17 | |
|
Major Dude
Join Date: Oct 2006
Posts: 1,892
|
Quote:
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. |
|
|
|
|
|
|
#18 |
|
Moderator
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 |
|
|
|
|
|
#19 |
|
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.
|
|
|
|
|
|
#20 |
|
Senior Member
Join Date: Mar 2006
Location: United States
Posts: 109
|
|
|
|
|
|
|
#21 |
|
Moderator
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 |
|
|
|
|
|
#22 |
|
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. |
|
|
|
|
|
#23 |
|
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.
|
|
|
|
![]() |
|
|||||||
| Thread Tools | Search this Thread |
| Display Modes | |
|
|