(nobody)
8/29/2010 8:42:00 AM
"Mike Williams" <Mike@WhiskyAndCoke.com> wrote in message
news:i5bcg0$jqb$1@speranza.aioe.org...
> Being a hobbyist I don't often get involved with file permissions when my
> code is run on other machines. I do know a few things about it, for
> example the behaviour of code running in a folder in the main Program
> Files folder and how it interacts with the current user's VirtualStore
> folder, but that's about all I know and I'd appreciate a little help on a
> specific matter.
>
> I know about it normally being best to write user data files only to the
> current user's data folder (for which I would use CSIDL_LOCAL_APPDATA),
> but
"Never" use CSIDL_LOCAL_APPDATA for settings, use CSIDL_APPDATA instead(if
you want to), along with CSIDL_FLAG_CREATE because the folder doesn't
necessarily exits, especially after a clean install, or after creating a new
user. This would work fine whether roaming is enabled or not. The "only"
legitimate use for CSIDL_LOCAL_APPDATA is for large files, like Temp files,
and a lot of email messages.
When a user logs in or out when roaming is enabled, his profile is
downloaded/uploaded to/from a server, except for what's in
CSIDL_LOCAL_APPDATA, so basically the user sees his documents and desktop
regardless of which computer he uses. HKEY_CURRENT_USER is a actually stored
in a file called "ntuser.dat", which is in the user's home folder, so this
get uploaded/downloaded too. This file is generally located in this
location:
XP: C:\Documents and Settings\<USERID>\ntuser.dat
Vista+: C:\Users\<USERID>\NTUSER.DAT
It's not necessarily mapped into HKEY_USERS.
> Anyway, this all works fine as far as I have tested it so far, but I'm
> wondering if I am doing this correctly, or are there perhaps any problems
> I am likely to run into, things that I might not have considered?
One thing that could bring a source of confusion to the user is when the
user uses one of the protected locations, and the settings file get
redirected elsewhere(In Vista+), so when the user copies back to the stick
again, he finds that the old settings where used. To force Vista+ to return
"Access is denied" to your app and stop redirecting, add asInvoker manifest
to your EXE. For example, if at startup you use WritePrivateProfileString()
to test if the INI file is writable, it would fail, and Err.LastDLLError
would be 5(ERROR_ACCESS_DENIED), so you can warn the user to choose another
location before using the program, or proceed anyway(in case the PC is
locked down by some software). Here is a function that you can use to test
if the file is writable(air code):
Public Function IsWritable(ByRef sFullFileName As String) As Boolean
Dim f As Long
On Error Resume Next
f = FreeFile
Open sFullFileName For Binary Access Read Write Shared As f
If Err.Number <> 0 Then
IsWritable = False
GoTo ExitSub
End If
Close f
IsWritable = True
ExitSub:
Err.Clear
End Function