From: milonass on
My application uses a xml settings file which can be changed from within the
application by the user. Now, under Windows 7 and Vista, I don't know where
to store this file. It is not possible to store it under Program Files\...
due to missing write access of non-administrators
What is the right place to store such files?

Thanks,
Thomas
From: Mikel on
On 25 jun, 12:50, milonass <milon...(a)discussions.microsoft.com> wrote:
> My application uses a xml settings file which can be changed from within the
> application by the user. Now, under Windows 7 and Vista, I don't know where
> to store this file. It is not possible to store it under Program Files\...
> due to missing write access of non-administrators
> What is the right place to store such files?
>
> Thanks,
> Thomas

Program Files\... was never the right place to store the application
settings, though earlier versions of Windows allowed it.

The right place would be one of the application data folders. You can
get them with ::SHGetFolderPath, by using CSIDL_APPDATA or
CSIDL_LOCAL_APPDATA. (These are the old API and IDs. They've
introduced SHGetKnownFolderPath for Vista, but that won't work with
XP, while the old one does work with Vista).

Those would be %USERPROFILE%\AppData\Roaming or %USERPROFILE%\AppData
\Local in Vista.
You would then append your "company name", or AfxGetApp()-
>m_pszRegistryKey, and/or maybe the app name, to the path, and store
the settings there.
From: Scott McPhillips [MVP] on
"milonass" <milonass(a)discussions.microsoft.com> wrote in message
news:FBF4D3D8-8AFB-4B43-88FE-698CF42B7C15(a)microsoft.com...
> My application uses a xml settings file which can be changed from within
> the
> application by the user. Now, under Windows 7 and Vista, I don't know
> where
> to store this file. It is not possible to store it under Program Files\...
> due to missing write access of non-administrators
> What is the right place to store such files?
>
> Thanks,
> Thomas

See the documentation for SHGetFolderPath. There are several options
available. Selecting CSIDL_LOCAL_APPDATA will return a path like
C:\Users\Milo\AppData\Local\YourAppName. The path is different for
different languages and OS versions, so you should use SHGetFolderPath to be
independent of these.

--
Scott McPhillips [VC++ MVP]

From: TomChapman on
So the example you show is in the "Users" tree. If the program is a
service do you use the same method to get a path. My programs are all
services. They usually run on desktops or servers that are dedicated for
my program.

Since they are a service they don't have a login user. Right?? So what
is appropriate here?


Scott McPhillips [MVP] wrote:
> "milonass" <milonass(a)discussions.microsoft.com> wrote in message
> news:FBF4D3D8-8AFB-4B43-88FE-698CF42B7C15(a)microsoft.com...
>> My application uses a xml settings file which can be changed from
>> within the
>> application by the user. Now, under Windows 7 and Vista, I don't know
>> where
>> to store this file. It is not possible to store it under Program
>> Files\...
>> due to missing write access of non-administrators
>> What is the right place to store such files?
>>
>> Thanks,
>> Thomas
>
> See the documentation for SHGetFolderPath. There are several options
> available. Selecting CSIDL_LOCAL_APPDATA will return a path like
> C:\Users\Milo\AppData\Local\YourAppName. The path is different for
> different languages and OS versions, so you should use SHGetFolderPath
> to be independent of these.
>
From: Joseph M. Newcomer on
It NEVER made sense to store in in the executable directory; historically, this has
*always* been a serious error; the only difference now is that you are prevented from
making this colossal blunder.

Use SHGetFolderPath to locate the user's AppData. You can download my ShGetFolderPath
Explorer from my MVP Tips site, which generates the code to actually do this, and you can
copy-and-paste it into your code.
joe

Here's the code it generated:

//----------------
// in stdafx.h
#define _WIN32_IE 0x500
#include <shlobj.h>
//-----------------
CString path;
LPTSTR p = path.GetBuffer(MAX_PATH);
HRESULT hr = ::SHGetFolderPath(CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, p);
if(SUCCEEDED(hr))
{ /* succeeded */
path.ReleaseBuffer();
...your code here
} /* succeeded */
else
{ /* failed */
path.ReleaseBuffer();
...failure code here
} /* failed */

On Fri, 25 Jun 2010 03:50:53 -0700, milonass <milonass(a)discussions.microsoft.com> wrote:

>My application uses a xml settings file which can be changed from within the
>application by the user. Now, under Windows 7 and Vista, I don't know where
>to store this file. It is not possible to store it under Program Files\...
>due to missing write access of non-administrators
>What is the right place to store such files?
>
>Thanks,
>Thomas
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm