how to find MyMusic Folder of other users ?
-
Which OS? The users folder is in a different location on Windows 7 and XP. – ChrisF Aug 16 '10 at 13:47
-
@ChrisF Judging by the response to my question, looks like he is looking for a version-agnostic method of doing it, which with windows api kinda sucks. – James Aug 16 '10 at 14:07
-
@ChrisF *response to my answer , not my question. – James Aug 16 '10 at 14:15
-
Duplicate of http://stackoverflow.com/questions/1059460/shgetfolderpath-for-a-specific-user – Anders Aug 16 '10 at 15:29
3 Answers
You can use the Environment.SpecialFolder
enum along with Environment.GetFolderPath
to get access to "special" user folders, like so:
Environment.GetFolderPath(Environment.SpecialFolder.MyMusic);

- 14,723
- 1
- 36
- 52
-
Sorry, I wasn't sure if "other users" referred to "users other than myself" (i.e. whoever runs the application, or "users other than the user accessing the application". – Ryan Brunner Aug 16 '10 at 13:56
The documented way to do this is to use SHGetFolderLocation and the hToken parameter, the problem is that you need the username and password to call LogonUser (You could also call WTSQueryUserToken if you are running as a service, but that limits you to the currently active sessions)
Now you are left with using undocumented stuff:
- Find the profile:
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList
(%windir%\Profiles on Win9x) - AdjustTokenPrivileges for
SE_RESTORE_NAME
- RegLoadKey NTUSER.DAT (USER.DAT on 9x)
- Query
HKEY_USERS\{SIDYOUGOTFROMPROFILELIST}\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
Note: You need to be admin to do this and it only works for local accounts.
If the account you are running the program on has administrative privlieges, can't you just navigate to c:\Users\<UserName>\Music
(which is the path on Windows7).
If you're looking for folders of users on another machine, then that is more difficult.
EDIT: It appears that there is a way to do this, from MSDN:
HRESULT SHGetKnownFolderPath(
__in REFKNOWNFOLDERID rfid,
__in DWORD dwFlags,
__in HANDLE hToken,
__out PWSTR *ppszPath
);
With the rfid being the KNOWNFOLDERID of the folder you are looking for in the case of My Music:
GUID{2112AB0A-C86A-4FFE-A368-0DE96E47012E}
Display NameMusicFolder
Type PERUSER
Default Path: %APPDATA%\Microsoft\Windows\Libraries\Music.library-msCSIDL
Equivalent None, new in Windows 7
Legacy Display Name Not applicable
Legacy Default Path Not applicable

- 2,454
- 1
- 22
- 22
-
-
then, this is a trickier problem than this solution will allow, but that is the default path. – James Aug 16 '10 at 14:01
-
-
This answer assumes that the default folders are correct. A users' profile does not have to reside on `C:\Users`. The remainder of the answer provides an MSDN link and a function from kernel32.dll, but no way to use it. Yes, the MSDN site has documentation, but it references several other functions and doesn't provide a complete workable solution, particularly in C#. Because this answer is terribly incomplete, I'm downvoting it. – Slogmeister Extraordinaire Jul 17 '17 at 19:36