I have a C++ command line program compiled with Microsoft Visual Studio 2003, and I am running the resulting 32 bit executable under Windows 7 (64 bit version). Most things work correctly except for one baffling oddness.
On startup, my program attempts to read a text file using and ifstream. If I run my program as an Administrator, either by opening an Administrator command prompt, or right clicking in Explorer and selecting “Run As Administrator”, then everything works fine and my program reads the current version of the file.
If instead, I run from a normal command prompt, or by double clicking in explorer, my program instead sees an older version of the text file from yesterday. Even if I delete the file, my program still happily opens the file and reads out the old contents.
If I run type or notepad on the file in non admin mode, the correct newest version displays, the problem appears limited to my program. I’ve tried giving every possible permission to the file to my user without any change.
One possible clue is that if I go to properties on the text file from Explorer and look under “Previous Versions”, there is one previous version listed, from yesterday, and it’s contents are identical to what my program is seeing when it tries to read the file.
Somehow my program appears to be stuck in an old view of the filesystem when running not as an administrator and is seeing this previous version instead, and am hoping someone can explain to me why this is happening and (hopefully) how to fix it.
If you are not using an absolute pathname for the input file, then you are likely reading the wrong file (evidenced by the fact that you can read the file after you delete it). In other words, there’s another copy of the old file somewhere on your system, and that’s what your program is reading.
Microsoft’s ProcMon tool (or the older FileMon) can show you which file is being accessed by your application.