Jump to content

  • Log In with Google      Sign In   
  • Create Account

Why is windows 7 deleting my files?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 Vortez   Crossbones+   -  Reputation: 2704

Like
0Likes
Like

Posted 05 May 2013 - 12:08 AM

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...).



Sponsor:

#2 MJP   Moderators   -  Reputation: 11774

Like
11Likes
Like

Posted 05 May 2013 - 12:34 AM

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.



#3 Eric Hobbs   Members   -  Reputation: 283

Like
2Likes
Like

Posted 05 May 2013 - 12:57 PM

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.


Edited by Eric Hobbs, 06 May 2013 - 11:48 AM.


#4 Aardvajk   Crossbones+   -  Reputation: 6216

Like
3Likes
Like

Posted 06 May 2013 - 04:45 AM

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.



#5 Vortez   Crossbones+   -  Reputation: 2704

Like
0Likes
Like

Posted 06 May 2013 - 06:21 PM

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?


Edited by Vortez, 06 May 2013 - 06:40 PM.


#6 Eric Hobbs   Members   -  Reputation: 283

Like
2Likes
Like

Posted 07 May 2013 - 12:35 AM

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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS