IOException Error 5?

I keep getting this crash error: (IOException Error 5) when I put together the install for my app and running it after the install when I try to save a file to disk within the app. It works PERFECTLY in the IDE I should point out.

The MSDN says it’s “Access Denied”. I’m using the Admin account and tried changing the install folder’s permissions, nothing works.

Has anyone had this and how do you deal with it?

“Access Denied” is not necessarily a permissions problem. The file may be in use, or you may be attempting to write to a read-only file, or you may be writing to a file which requires privilege elevation (right-click the EXE and run as administrator.)

Hmm, the only time the files are used is when a game is saved, which is infrequently. When I compile the app, install it using an installer, and run it, it can’t delete or write to any files at all.

I use this for accessing the file:

#if DebugBuild f = getfolderitem("").Parent.Child("soc1.txt") #else f = getfolderItem("soc1.txt") #endif

Note: If I set it to run as admin, it seems to work ok. I am running the admin account though.

If you installed it in Program Files, then you need elevated permissions (run as admin) in order to write to the local folder, regardless of what user is running the program. Storing a file locally is always a bad idea. You might want to consider storing it in SpecialFolder.ApplicationData or SpecialFolder.Documents, depending on whether you want it visible to the user.

Tim: Maybe SpecialFolder.ApplicationData (user doesn’t need to see the files)? How would I modify the code above to use that instead? Will that work with Windows Vista/7/8?

f = SpecialFolder.ApplicationData.Child("soc1.txt")

Although it would be better to create a subfolder for your app. If you do this you can do away with the #If DebugBuild as well the data won’t be lost between debug runs.

I get Exception Error 5 on Windows 7 but not on XP!

Yes, that’s right. Things changed. Security got tighter.
This is why many win 9x and XP applications fail under Windows 7 and later.

But my QB app works fine with Windows 7 - the problem has only been with the one created by Xojo.

Your QB app obviously doesn’t try to write to the install directory. It already uses ApplicationData. You need to update your Xojo app to write to the right place.

Thanks, but how do I do that?

I have not changed my code in the file save area in awhile but on Windows 7 I started
getting an IOException 5 and my app DOES write to the ApplicationData folder.

Anyone know if Microsloth tightened the security on Windows 7 even more in the last few months???

If I run my app as administrator I don’t get the problem.

Sometimes, I do not know when this happens, ownership was taken by the windowssystem, instead of the accountname the file was made in (even when you are admin).

Select:
your file --> properties --> security --> advanced

Check if the file is owned by your account or by an account where your account is member of.
If not, then takeover ownership.

You can only do this action when you are admin.