Why is windows 7 deleting my files?

Started by
4 comments, last by ericthobbs 10 years, 11 months ago

So, i have this program that save it's settings using a .bin file, it work normally under xp, but in windows 7, since i disabled uac it keep deleting it after each reboot, what's wrong??? And im running on an admin acount... do i have to give the file special permision or something?

Is it because the file is in program files (x86) folder?

I really hate windows 7 over-security problem, it's just constantly get in the way of what you are trying to do... I guess ill have to use the registry, at least it wont delete my key (i hope...).

Advertisement

On Vista/Win7/Win8 users normally run with lowered privileges, which can be temporarily elevated using a UAC prompt. This changed from XP, where by default users had full admin privileges for everything. They did this so that programs don't gain full admin access unless the user is specifically allows it, in order to prevent malicious programs from doing whatever they want. Since you're complaining about this, I'll note that this is standard on Unix-like systems where users don't normally just login as root and will instead use the su command to temporarily elevate privileges.

Anyway the point is that you can't write to the Program Files directory without admin-level privileges, which normally requires a UAC elevation prompt. So you don't want to use it to store settings or temporary files. Instead you're supposed to store per-user data in FOLDERID_RoamingAppData (usually located in C:\Users\username\AppData\Roaming), and non-user-specific data in FOLDERID_ProgramData (usually located in C:\ProgramData). You can read about these special folders here.

So, i have this program that save it's settings using a .bin file, it work normally under xp, but in windows 7, since i disabled uac it keep deleting it after each reboot, what's wrong??? And im running on an admin acount... do i have to give the file special permision or something?

Is it because the file is in program files (x86) folder?

It might be due to UAC Folder Virtualization.

see http://msdn.microsoft.com/en-us/gg465124

I really hate windows 7 over-security problem, it's just constantly get in the way of what you are trying to do... I guess ill have to use the registry, at least it wont delete my key (i hope...).

Its not overly secure and for most scenarios you want settings and other volatile data to be per user anyway so you shouldn't be writing to a global directory, like program files, anyway.

Note also: the registry is also virtualized so if you try to write to HKEY_LOCAL_MACHINE without elevated permissions, it will be redirected to a virtual area under HKEY_CURRENT_USER.

As above, UAC is just fine and the virtualization was essential for backwards compatibility. The "problem" occurs when you aren't respecting the modern rules which are there for good reasons.

Thx for the replys, i'll take a look at the ms stuffs when i have the time.

EDIT: The file was not deleted, but the settings didn't load for some reason, guess ill have to reproduce the bug in vmware.

Also, i can't add "Enable UAC" in vs because my programs interface is build using Delphi 6 (but most of the code is loaded from c++ dlls).

So, what's the best way to save programs settings nowaday?

You do like MJP suggested and get the path to the Application Data directory via the appropriate API calls. Google searching "Delphi <FOLDERID>" where <FOLDERID> is the name of the constant that MJP pointed out might lead you down the correct path.

This topic is closed to new replies.

Advertisement