Converting "User Shell Folders" registry value to actual path
The following registry key contains many system default folder locations.
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
The value for the path of the All Users desktop, which is found there, is as follows:
XP or earlier : %ALLUSERSPROFILE%\Desktop
Vista or later: %PUBLIC%\Desktop
Whereas the actual paths of the All User desktops, respectively, are as follows:
XP or earlier : "C:\Documents and Settings\All Users\Desktop"
Vista or later: "C:\Users\Public\Desktop"
Now, if you use copy and paste the above registry values in Windows Explorer and hit enter it takes you to the actual folders. For example, if you paste [%PUBLIC%\Desktop] in a Windows Explorer in Vista it takes you to ["C:\Users\Public\Desktop"].
My question is this; how do I reproduce this behavior from withing a C# program? To be more specific, if I retrieve the registry value [%PUBLIC%\Desktop] from withing a C# program, which I can do easily, how do I convert it to ["C:\Users\Public\Desktop"]? Obviously I'm not looking for a string replacement, I need to do what Windows does.
sachintha81
Junior Poster in Training
96 posts since Apr 2008
Reputation Points: 35
Solved Threads: 1
finito
Nearly a Posting Virtuoso
1,321 posts since May 2010
Reputation Points: 60
Solved Threads: 135
sachintha81
Junior Poster in Training
96 posts since Apr 2008
Reputation Points: 35
Solved Threads: 1
Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
from http://www.daniweb.com/forums/thread281763.html
Oh and if you hinting me that I should go through the Documents and Settings directory to find all the available user profiles then that is not what I'm looking for. I'm confused anyway.
sachintha81
Junior Poster in Training
96 posts since Apr 2008
Reputation Points: 35
Solved Threads: 1
ok let me step back and ask you didn't you want [%PUBLIC%\Desktop] ?
Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
this will get you the desktop path.
finito
Nearly a Posting Virtuoso
1,321 posts since May 2010
Reputation Points: 60
Solved Threads: 135
ok let me step back and ask you didn't you want [%PUBLIC%\Desktop] ?
Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
this will get you the desktop path.
Thanks for the reply finito.
But I feel like we're missing something here. The path indicated by [%PUBLIC%\Desktop] is the All User Desktop path (usually "C:\Users\Public\Desktop" in Vista), while
Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
returns the current user's desktop path. Usually something like this:
"C:\Users\[Current User Name]\Desktop"
sachintha81
Junior Poster in Training
96 posts since Apr 2008
Reputation Points: 35
Solved Threads: 1
I am sorry didn't read properly you want public.
Environment.ExpandEnvironmentVariables(@"%ALLUSERSPROFILE%\Desktop")
finito
Nearly a Posting Virtuoso
1,321 posts since May 2010
Reputation Points: 60
Solved Threads: 135
I am sorry didn't read properly you want public.
Environment.ExpandEnvironmentVariables(@"%ALLUSERSPROFILE%\Desktop")
Oh glad we got it resolved finally.
:cool:
Btw, I tried to retrieve the said registry key and apparently the .NET framework automatically calls the method you specified when reading the registry entry. So, guess we both are correct.
Thanks again!
sachintha81
Junior Poster in Training
96 posts since Apr 2008
Reputation Points: 35
Solved Threads: 1