5
votes

I need to write a ini file to the current user's directory in Windows 7 (C:\Users\CurUser). CurUser is not an admin. My installer requires admin privileges. So my setup looks like this:

[Setup]
PrivilegesRequired=admin

When I run the installer it prompts for the admin to login. From that point on, all the user constants, userappdata, etc, are C:\Users\AdminUser... So I need a way to find the CurUser when running the install as AdminUser.

Code examples are appreciated. Thanks.

3
Don't know if it's possible, as you are now running the setup.exe under the admin user, and I don't think it has any knowledge of the user that requested privileges.Robert Love
Is it possible to search for the dir I'm looking for with Inno? I know the dir is *\abc\xyz\.PM2
You can use FindFirst, FindNext, and FindClose routines to find directories.Robert Love
I found an example using the Find*, but I'm still having trouble getting it to locate my directory. I tried FindFirst('*.ini', 0) and it found desktop.ini. So then I tried finding an ini files that lives in the directory that I'm looking for [FindFirst('test.ini', 0)] and it didn't find it. I also tried '*test.ini'. What I'd really like to do is find the actual directory which is named like this '.abc'. I've had zero luck finding a directory. I need something like this 'C:*\.abc'. I'm guessing I have my wildcards wrong.PM2
It's not that smart. It searches the specified directory so you have to recursively call the routine for each directory found.Robert Love

3 Answers

3
votes

All user specific files/settings that the app requires should be written by the app if they are found not to exist. If it needs to come from the setup, you can write it into a global location as a "default" for the app to copy or use.

This also means your app will work for ALL users on the system rather than just the user that ran the setup.

3
votes

You should split your setup into two parts. The first non-admin part writes the ini file to the current user directory and it calls the second setup part which requires admin priviliges.

1
votes

In my case, I just switched to {commonappdata} instead of {appdata}, as my data was the same for all users.