<a href="http://www.micropoll.com/akira/mpview/585320-168921">Click Here for Poll</a><a href="http://www.questionpro.com" title="online surveys">Online Survey</a><BR> | <a href="http://www.micropoll.com" title="Website Polls">Website Polls</a><BR> | <BR><a href="http://www.micropoll.com/akira/MicroPoll?mode=html&id=168921">View MicroPoll</A></div>

Visual Studio 2010!

Read now >

Windows Mobile Development Thoughts

Read now >

View Now
DevSource RSS FEEDS
XML Want an easy way to keep up with breaking tech news? And the Get DevSource headlines delivered to your desktop with RSS.
ADVERTISEMENT
ADVERTISEMENT

 

DevSource.com: Your Source for Visual Studio on Facebook
ADVERTISEMENT
Finding the User Settings in Vista
By John Mueller

Rate This Article: Add This Article To:

Finding the User Settings in Vista - ' Using Junctions '
( Page 2 of 4 )

Most programming manuals warn about the problems associated with hard-coding file and setting locations in the applications you write. After all, the user could move those items anywhere; and if the locations are hard coded, the application could fail to work as anticipated.

Often, developers overcome this problem by using various tricks, including creating a new version of the file in the required location. The only problem is that nobody assumed that Microsoft would make massive changes to the folder layout in Windows Vista — apparently for no reason at all.

Which is precisely what they've done.

Using Junctions for Existing Folders

I haven't talked with anyone who has a good idea about why Microsoft made the "Documents and Settings" folder in Vista a junction. The only idea I've come up with is that some applications had problems accessing folders with spaces in the name. You'll find the settings in the "Users" folder now; the "Documents and Settings" folder is a thing of the past.

Of course, the first question many people ask is what junctions are, followed closely by how to use them. A junction is essentially a link to another folder on the system. In theory, it works the same as accessing that folder. However, in practice, using junctions can cause problems because your application might not find the data it needs.

For more info: That's the short view of junctions. You can read the Microsoft version here, and a more understandable third-party explanation here. You can see how to create and manipulate junctions in this Microsoft Knowledge Base article.

Just in case you're interested, the .NET Framework doesn't provide the functionality required to create junctions currently. However, you can use PInvoke to create and manage junctions using the Distributed File System (DFS) Win32 API calls NetDfsAdd(), NetDfsRemove(), NetDfsEnum(), NetDfsGetInfo(), and NetDfsSetInfo(). Unfortunately, there's very little information available about these calls right now. You can, however, see a prototype for the NetDfsAdd() function here; that Web site includes prototypes for the other functions as well. You should also check John Hines' Code Blog.

Locating the Folders

It wouldn't be so bad if Microsoft had simply made one change. However, Microsoft has moved a lot of directories that affect common user folders. Here's a quick chart to show you the before-and-after.
Was Now
Application Data AppData\Roaming
Cookies \AppData\Roaming\Microsoft\Windows\Cookies
Local Settings \AppData\Local
My Documents \Documents
NetHood \AppData\Roaming\Microsoft\Windows\Network Shortcuts
PrintHood \AppData\Roaming\Microsoft\Windows\Printer Shortcuts
Recent \AppData\Roaming\Microsoft\Windows\Recent
SendTo \AppData\Roaming\Microsoft\Windows\SendTo
Start Menu \AppData\Roaming\Microsoft\Windows\Start Menu
Templates \AppData\Roaming\Microsoft\Windows\Templates

You'll notice that all of these new locations lack spaces, which is why I mentioned earlier that the use of spaces could have caused problems. It's also interesting to note that the \AddData folder has a Roaming, Local, and LocalLow folder to store settings. You'll need to be careful where you store settings, because you don't want to use the \AppData\Local folder to store data a user might require on another computer.

Also, some generic user folders have moved as well. The \Documents and Settings\Default User folder is now located in \Users\Default. The \Documents and Settings\All Users folder has also moved, but I can't provide you with a precise location for it.

Vista now lets you use an entirely new kind of link called the symbolic link. You even use a special utility to work with symbolic links, as explained here. The symbolic links appear in a directory list with a SYMLINKD notation.

Figure 1: Windows Explorer shows junctions and symbolic links to existing folders as shortcuts.

Unfortunately, Vista hides most of these changes from view. You need to set Windows Explorer to show hidden files and hidden operating system files. The junctions and symbolic links both appear in Windows Explorer as shortcuts, as shown in Figure 1.

It's not until you open a command prompt and type Dir /ah (to show the hidden files) that you see the difference, as shown in Figure 2.

Figure 2: The Vista command prompt shows you a different view where you can determine the difference.

In Figure 2, you can see a symbolic link <SYMLINKD>, directory <DIR>, and a junction <JUNCTION>. If nothing else, Figure 2 illustrates the need for developers to use the command prompt when finding special files and settings.

At this point, you can see the need to use coding techniques that rely on the operating system to find a file for you, rather than hard coding the file locations as part of the application. Vista promises to provide a difficult application environment for developers who refuse to make the change.



 
 
>>> More Using Microsoft Visual Studio Articles          >>> More By John Mueller