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.

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.

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.

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"

I am sorry didn't read properly you want public.

Environment.ExpandEnvironmentVariables(@"%ALLUSERSPROFILE%\Desktop")

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.