Don’t Write User Files to ...

Share your advanced PureBasic knowledge/code with the community.
sec
Enthusiast
Enthusiast
Posts: 792
Joined: Sat Aug 09, 2003 3:13 am
Location: 90-61-92 // EU or ASIA
Contact:

Don’t Write User Files to ...

Post by sec »

I am reading a book, and has some useful info so i put it here:
Don’t Write User Files to \Program Files
Writing to the \Program Files directory requires the user to be an administrator because the access control entry (ACE) for a user is Read, Execute, and List Folder Contents. Requiring administrator privileges defeats the principle of least privilege. If you must store data for the user, store it in the user’s profile: %USERPROFILE%\My Documents, where the user has full control. If you want to store data for all users on a computer, write the data to \Documents and Settings\ All Users\Application Data\dir.

Writing to \Program Files is one of the two main reasons why so many applications ported from Windows 95 to Windows NT and later require the user to be an administrator. The other reason is writing to the HKEY_LOCAL_MACHINE portion of the system registry, and that’s next.
------
Don’t Write User Data to HKLM
As with writing to \Program Files, writing to HKEY_LOCAL_MACHINE is also not recommended for user application information because the ACL on this registry hive allows users (actually, Everyone) read access. This is the second reason so many applications ported from Windows 95 to Windows NT and later require the user to be an administrator. If you must store data for the user in the registry, store it in HKEY_CURRENT_USER, where the user has full control.
Tranquil
Addict
Addict
Posts: 952
Joined: Mon Apr 28, 2003 2:22 pm
Location: Europe

Post by Tranquil »

Intresting to know! Thanks for sharing this knowledge.

Mike
Tranquil
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Re: Don’t Write User Files to ...

Post by GPI »

> If you must store data for the user, store it in the user’s profile: %USERPROFILE%\My Documents

ARGHHHHH!!!!!!!!!!!! DON'T DO THIS! I HATE THIS! (And don't write in the regestry)

And by the way: On my system no My Documents exist.


>\Documents and Settings\ All Users\Application Data\dir.

Same here

Don't not use fixed-System-Paths. Always ask the correct path with api-commands.

GPI
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

erhm.. what about win 95/98/me?
LarsG
Enthusiast
Enthusiast
Posts: 713
Joined: Mon Jun 02, 2003 1:06 pm
Location: Norway
Contact:

Post by LarsG »

- Don't write to the registry.
- All configuration stuff should be in the program directory (ie. where the user has installed your program)
- All the data should either be put in the program directory (perhaps in a subfolder), OR to a directory which the user has specified.

This way I know where everything is placed, and in addition, I can move the app to another HDD if I want to , and it would still work.

My 2 cents.

AMD Athlon XP2400, 512 MB RAM, Hercules 3D Prophet 9600 256MB RAM, WinXP
PIII 800MHz, 320 MB RAM, Nvidia Riva Tnt 2 Mach 64 (32MB), WinXP + Linux
17" iMac, 1.8 GHz G5, 512 MB DDR-RAM, 80 GB HD, 64 MB Geforce FX 5200, SuperDrive, OSX
filperj
User
User
Posts: 77
Joined: Tue Sep 16, 2003 8:53 pm
Location: Nevers(France)

Post by filperj »

This way I know where everything is placed, and in addition, I can move the app to another HDD if I want to , and it would still work.
I all agree ^^
And an app wich is registry dependant won't work correctly after a system reinstallation.
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

Well, don't also forget to write stuff to NIL:

It's a very bad idea !
texxsound
User
User
Posts: 11
Joined: Sun Aug 29, 2004 12:04 pm
Location: Austria, EU

Re: Don’t Write User Files to ...

Post by texxsound »

GPI wrote:> If you must store data for the user, store it in the user’s profile: %USERPROFILE%\My Documents

ARGHHHHH!!!!!!!!!!!! DON'T DO THIS! I HATE THIS! (And don't write in the regestry)

And by the way: On my system no My Documents exist.


>\Documents and Settings\ All Users\Application Data\dir.

Same here

Don't not use fixed-System-Paths. Always ask the correct path with api-commands.

GPI
Yep, hate it too! Really! I hate it so much that i wrote a simple .BAT that deletes every "My Videos" "My Music" "My Whatever" folder during booting.
When will they ever learn... ;)
Some do code in sweet delight, some do code in endless night
Doobrey
Enthusiast
Enthusiast
Posts: 218
Joined: Sat Apr 26, 2003 4:47 am
Location: Dullsville..population: me
Contact:

Re: Don’t Write User Files to ...

Post by Doobrey »

Years ago, I did a similar batch file to clean up winblows on startup.
When I tried it, it seemed to take forever to finish..then I noticed my C:\windows\ dir was now empty :oops:
Post Reply