itsmeandnobodyelse
asked on
How to retrieve the user's "My Documents" folder
I want to copy some document templates to the user's "My Documents" folder at setup time. In my C++ program I need to read from that folder. Though the folder mostly is located at "%userprofile%\My Documents" there is a chance that the user moved it to some other path.
I found out that the path of the folder was stored in registry at "HKEY_CURRENT_USER\Softwar e\Microsof t\Windows\ CurrentVer sion\Explo rer\Shell Folders\Personal". I easily could read that value in C++.
I also found a VB code snippet by googling that retrieves the folder name by
from win32com.shell import shell
df = shell.SHGetDesktopFolder()
pidl = df.ParseDisplayName(0, None,
"::{450d8fba-ad25-11d0-98a 8-0800361b 1103}")[1]
mydocs = shell.SHGetPathFromIDList( pidl)
I am weak in VB but I think I would be able to convert the snippet to C++.
I have a few questions related to that:
1. Are these solutions equivalent and valid? Means, do they always retrieve a valid path name?
2. Isn't there an easier solution, e. g. using a predefined name like %mydocs%?
3. If not, does anyone know another solution that can be used in a batch file?
Thanks in advance
Regards Alex
I found out that the path of the folder was stored in registry at "HKEY_CURRENT_USER\Softwar
I also found a VB code snippet by googling that retrieves the folder name by
from win32com.shell import shell
df = shell.SHGetDesktopFolder()
pidl = df.ParseDisplayName(0, None,
"::{450d8fba-ad25-11d0-98a
mydocs = shell.SHGetPathFromIDList(
I am weak in VB but I think I would be able to convert the snippet to C++.
I have a few questions related to that:
1. Are these solutions equivalent and valid? Means, do they always retrieve a valid path name?
2. Isn't there an easier solution, e. g. using a predefined name like %mydocs%?
3. If not, does anyone know another solution that can be used in a batch file?
Thanks in advance
Regards Alex
You should be able to use SHGetSpecialFolderLocation
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
For your requirements, you'll want to use CSIDL_MYDOCUMENTS or CSIDL_COMMON_DOCUMENTS.
hr = SHGetSpecialFolderLocation (0,
CSIDL_MYDOCUMENTS, &pidl);
hr = SHGetSpecialFolderLocation
CSIDL_MYDOCUMENTS, &pidl);
For this code you need shell32.lib, and you should have the latest SDK installed.
ASKER
>>>> SHGetSpecialFolderLocation
Unfortunately, SHGetSpecialFolderLocation has no predefined index for the "My Documents" folder. There is no id like CSIDL_DESKTOPDIRECTORY.
Regards, Alex
Unfortunately, SHGetSpecialFolderLocation
Regards, Alex
ASKER
>>>> CSIDL_MYDOCUMENTS
That id doesn't exist on my VC6 system. Does it come with VC7 or VC8?
Did you know of CSIDL_PERSONAL?
Regards, Alex
That id doesn't exist on my VC6 system. Does it come with VC7 or VC8?
Did you know of CSIDL_PERSONAL?
Regards, Alex
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
>>>> and you should have the latest SDK installed.
That might become a problem cause it's a customer's environment.
Do you know whether the registry solution (Q1) is valid?
Regards, Alex
That might become a problem cause it's a customer's environment.
Do you know whether the registry solution (Q1) is valid?
Regards, Alex
ASKER
>>>> Seems to me like your ... setting is a better bet.
I found the folder path in
HKEY_CURRENT_USER\Software \Microsoft \Windows\C urrentVers ion\Explor er\Shell Folders\Personal
and
HKEY_CURRENT_USER\Software \Microsoft \Windows\C urrentVers ion\Explor er\User Shell Folders\Personal
What do you think is the better one?
Regards, Alex
I found the folder path in
HKEY_CURRENT_USER\Software
and
HKEY_CURRENT_USER\Software
What do you think is the better one?
Regards, Alex
ASKER
>>>> CSIDL_PERSONAL
I found it in shlobj.h. I'll give it a try.
Regards, Alex
I found it in shlobj.h. I'll give it a try.
Regards, Alex
"User Shell Folders" is the per user one, methinks. Presumably "Shell Folders" is for any user created by the user?? Sorry, I'm guessing Alex.
>>That id doesn't exist on my VC6 system. Does it come with VC7 or VC8?
As I stated, you need to have the latest SDK on your machine.
CSIDL_MYDOCUMENTS works with VC6 if you have the latest SDK installed.
As I stated, you need to have the latest SDK on your machine.
CSIDL_MYDOCUMENTS works with VC6 if you have the latest SDK installed.
>>you don't appear to have the definitive way to find My Documents
You do have a definitve way. Just use CSIDL_MYDOCUMENTS.
You do have a definitve way. Just use CSIDL_MYDOCUMENTS.
According to http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/functions/shgetspecialfolderlocation.asp you should use http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/functions/shgetfolderlocation.asp with CSIDL_MYDOCUMENTS for Windows 2000+, but I guess there still exist Windows 98 users.
>>Did you know of CSIDL_PERSONAL?
I've never used it, but here's what MSDN saids about it:
CSIDL_PERSONAL (0x0005)
The file system directory used to physically store a user's common repository of documents. A typical path is C:\Documents and Settings\username\My Documents. This should be distinguished from the virtual My Documents folder in the namespace, identified by CSIDL_MYDOCUMENTS. To access that virtual folder, use SHGetFolderLocation, which returns the ITEMIDLIST for the virtual location, or refer to the technique described in Managing the File System.
From above statement, it's not very clear to me what's the difference between CSIDL_PERSONAL and CSIDL_MYDOCUMENTS.
I've never used it, but here's what MSDN saids about it:
CSIDL_PERSONAL (0x0005)
The file system directory used to physically store a user's common repository of documents. A typical path is C:\Documents and Settings\username\My Documents. This should be distinguished from the virtual My Documents folder in the namespace, identified by CSIDL_MYDOCUMENTS. To access that virtual folder, use SHGetFolderLocation, which returns the ITEMIDLIST for the virtual location, or refer to the technique described in Managing the File System.
From above statement, it's not very clear to me what's the difference between CSIDL_PERSONAL and CSIDL_MYDOCUMENTS.
>>but I guess there still exist Windows 98 users.
You could add extra logic in the code for Win9x machines.
You could add extra logic in the code for Win9x machines.
>>>you don't appear to have the definitive way to find My Documents
>You do have a definitve way. Just use CSIDL_MYDOCUMENTS.
I meant using 450d8fba-ad25-11d0-98a8-08
ASKER
>>>> You do have a definitve way. Just use CSIDL_MYDOCUMENTS.
It works with CSIDL_PERSONAL.
>>>> Sorry, I'm guessing Alex.
No problem. It's most likely redundant.
I will use Axter's way for the programmatical access and the registry way for the batch (cause I already have a prog that was able to assign an environtment variable with a registry entry).
Regards, Alex
It works with CSIDL_PERSONAL.
>>>> Sorry, I'm guessing Alex.
No problem. It's most likely redundant.
I will use Axter's way for the programmatical access and the registry way for the batch (cause I already have a prog that was able to assign an environtment variable with a registry entry).
Regards, Alex
Are you guys getting a major lag for email notification?
I'm getting email notifications about 15-30 minutes later.
I'm not sure if it's my server, or EE.
I'm getting email notifications about 15-30 minutes later.
I'm not sure if it's my server, or EE.
ASKER
>>>> Are you guys getting a major lag for email notification?
No, the lags I had in the thread here have been due to typing lags. My notifications have been in the same minute as in EE.
Regards, Alex
No, the lags I had in the thread here have been due to typing lags. My notifications have been in the same minute as in EE.
Regards, Alex
> Are you guys getting a major lag for email notification?
It's quick for me too.
It's quick for me too.
Must be my server then.
Thanks
Thanks
You may be able tell where the hold-up is by looking at the chain of "Received:" headers (weirdly this is View | Options in MS Outlook).