open statement and virtualstore

open statement and virtualstore

Hi there,

I just encountered a strange problem and here is the solution to it. Maybe someone will help this post :-)

In short: To avoid UAC problems, use "READONLY" or "ACTION=READ" to open files when just want to read a file. I always opened a file by default in readwrite mode because I ommited the action statement. But because of readwrite, this happened to me:

For my latest project I had to create a deployment mechanism, so I created an installer project in my solution that creates a msi package. It simply installs a few executables and text config files in the program files folder.

A few days later I made an update to the project and changed a text config file, rebuild the installer and installed it to a clients machine. But the project wouldn´t work. Somehow the text config file wasn´t recognized by the program. So I opened the program files folder and looked at the text file. It was the new one. Opened it by command line. It was the new one. I put write statements in my project to see what it has read. It was the old one. But how could it a read the old one? There is the new in the folder. Doubled checked it.

When asking a colleague at work he had an idea. A compatibilty feature of Windows Vista and Windows7 (8, I don´t know) creates a virtualstore folder when you want to write a file in the program files folder. Because writing in program files was common in Windows XP and forbidden in Vista this feature stores newly written files not in C:\Program Files (x86) but in C:\Users\UserName\AppData\Local\VirtualStore\Program Files (x86). When I opened a text file in readwrite mode, Windows7 created a copy in this VirtualStore folder and used this one. Even when my installer wrote a new file in my normal program files folder there was the old one in the VirtualStore folder. And this one was opened all the time.

So, the solution was to use "open(newunit=iunit, file=filename, readonly)" instead of "open(newunit=iunit, file=filename)".


3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Good work Markus.

To me, this seems to be an oversight (bug) in Windows. Additionally you could consider this an oversight in the installation program (or use of older installation program than Vista).

Jim Dempsey


This issue should be highlighted for all fortran users moving from XP to Windows 7. ( I'm yet to learn what Windows 8 has changed! )

The way that Windows 7 has restricted the use of some commonly used directories, such as c:\ and c:\windows for .ini files has been a frustrating learning experience for me also. This has required patches to many old .exe programs, often struggleing to find the source.

ACTION='READ' is Fortran95 conforming and is preferable to 'READONLY'

Thanks for highlighting this anoying problem.


Leave a Comment

Please sign in to add a comment. Not a member? Join today