cwindowswinapiappdatavirtualstore

GetPrivateProfileString and AppData VirtualStore directory


I have a program which reads GetPrivateProfileString from a file ".\abcd.ini" - i.e. it will look for the ini file in the current directory. If it does not find the ini file, it has a default value set in the 3rd parameter to GetPrivateProfileString.

I have an installer which installs the program to c:\program files (x86)\abcd\client directory.

Initially, the installer also installed an abcd.ini file in the same directory with a particular profile string key/value pair. Post that, I changed the installer to not install any ini file.

However, the program continued taking the value from the old ini file which I had shipped even if it didn't exist in that directory.

After doing a system wide search I found a copy of abcd.ini in c:\Users\myusername\AppData\Local\VirtualStore\Program Files (x86)\abcd\Client

Once I deleted this, the program worked correctly (as if there is no ini file).

Googling it seems that the virtualstore is used because myuser does not have full permissions for c:\program files (x86). However, the program itself doesn't write to the ini file, it only reads from it.

Is this actually how it's supposed to be? Why is the ini file copied to AppData & why does the program read from there if there is no local copy?

I am on Windows 10 64 bit.


Solution

  • The diagnostic is that the EXE program does not contain a manifest that declares itself compatible with UAC. Not unusual for the kind of app that still uses GetPrivateProfileString().

    Is this actually how it's supposed to be?

    Yes, this the way modern versions of Windows (major version >= 6, Vista and up) deal with legacy programs that assume the user always has admin privileges. Redirecting the file access to the VirtualStore directory ensures that the missing access rights to Program Files directory does not cause trouble.

    it only reads from it

    The OS does not have a time machine to guess whether you might write to the file and did so in a previous session. So it has to check the VirtualStore directory first. To find that .ini file.

    It is also important to not assume that it was your program that got the .ini file in that directory. It could have been done by another ancient program, like a text editor. Or a previous version of your program. Or the installer you use.