4
votes

I normally write my Delphi applications with an INI file saved in the application's own folder:

ConfigFile:= ChangeFileExt(ParamStr(0), '.ini');
IniFile:= TIniFile.Create(ConfigFile);

try
  with IniFile do
  begin
    // etc

However, one particular application I'm writing, I want to use a setup wizard (Inno) and also give users the opportunity to install the app in Program Files (x86)\MyProg.

What is new to me is that Windows doesn't save the INI file in the install directory but "somewhere else".

Uninstalling the app through Control Panel successfully removes all the items from the Program Files (x86) folder (including the folder) but - in common with a lot of programs - if it is re-installed, all the configuration settings are restored. So they must be stored somewhere that Control Panel | Uninstall doesn't remove.

So my question is where?

Thanks, John.

1
You're violating the Windows guidelines by writing to Program Files from your application. That's been verboten since Vista was released (actually XP, but they didn't enforce it until Vista). Writes to Program Files are virtualized to a different folder. Even if you choose to use a 15 year old development tool, you need to adjust your software to keep up with modern versions of the OS.Ken White
Stop looking for the file and learn about the changes introduced in Vista, 11 years ago. Then add an app manifest, stop virtualization, and store the file under the user profile.David Heffernan
How to make Delphi programs Vista-aware (which as David says is over a decade old) should help.Ken White
Hey John, I recommend you learn about how to explicitly specify a modern location for your configuration files, instead of flinging it into the UAC Folder virtual store, which is what you just did.Warren P

1 Answers

3
votes

Writing files underneath the Program Files folders is forbidden by non-admin users. If an app running as a non-admin user tries to write a file there, and the app does not have an UAC manifest, then Windows protects the Program Files folder and silently redirects all access to a VirtualStore folder within the user's profile.

Common file and registry virtualization issues in Windows Vista or in Windows 7

Windows 7 Application Compatibility Issues …Demystified !!!

In this case, when you write your INI to this file:

C:\Program Files (x86)\MyProg\MyProg.ini

It is actually written to this file instead:

%USERPROFILE%\AppData\Local\VirtualStore\Program Files (x86)\MyProg\MyProg.ini

You should change your app to store the INI file in a more appropriate location, such as:

%LOCALAPPDATA%\MyProg\MyProg.ini

Or:

%PROGRAMDATA%\MyProg\MyProg.ini

Where Should I Store my Data and Configuration Files if I Target Multiple OS Versions?