Brent Gardner's Blog

It's all about the code.

Syndication

Tags

    No tags have been created or used yet.

Navigation

.NET and DFSR

Recently I was tasked to create some automated tools that could configure DFSR. If you are not familiar with it, Microsoft has combined DFS (distributed file system) and FRS (file replication service); two fantastic technologies that give Windows Server users the ability to have redundant network drives. The combination of services is now called DFSR, and was a pretty logical and intelligent move. Unfortunately its seems that Microsoft didn't get around to creating an SDK for this technology before they sent it out the door, which pretty much leaves users with two options:

  1. The DFS / FRS API's (http://msdn2.microsoft.com/en-us/library/aa379538.aspx). While these seem to work well enough, they are more or less legacy, and don't have the cool new additions of DFSR, and since they have no managed namespace equivalent, they are a little cumbersome to use from .NET.
  2. The new DFSR WMI provider (http://msdn2.microsoft.com/en-us/library/aa380990.aspx). This is quite handy because it is easily accessible from managed code, and it contains all the latest DFSR stuff. The problem is that it seems to be read-only! (or at least I couldn't find any write methods, and calls to ManagementObject.Put() fail with a generic exception).

There is however a MMC snap-in included with Windows Server 2003, so there must be an API out there somewhere right? After some quick poking around its possible to see that the dfsmgnt.msc file loads DfsMgmt.dll, which in turn loads DfsObjectModel.dll. As the name implies, this .dll has a beautifully constructed object model for .NET. One look with Lutz Roeder's fantastic program Reflector (http://www.aisto.com/roeder/dotnet/) quickly reveals a logical class system neatly representing the underlying DFSR objects. The only problem being that all the classes are marked as "friend", so we can't simply import the assembly and use it ourselves!

Luckily what Microsoft taketh-away, they also giveth-back. Using reflection, it is possible to instantiate classes and call methods, even if they aren't exposed. Since there seems to be no clean alternative method for accessing DFS through .NET, I've created a some simple wrapper classes which re-expose the friend methods in this .dll.

The code listed below is by no means considered to be a complete recreation, but hopefully it will be a good starting point for others to build on. Bear in mind you will need to:

  • Create a DFS root to start with
  • Have a domain 
  • Have at least one server with DFS installed (two would make more sense ;-)
  • Compile the small forms app with Visual Studio .NET 2005
  • Copy the DfsObjectModel.dll file from a Windows 2003 server into the \Bin\Debug folder prior to running this app
  • Update the textbox values to reflect the appropriate values for your environment
  • Bear in mind this is example code, not intended for production deployment!

Download DFS.zip

- Brent

Published Monday, April 09, 2007 12:54 PM by Brent


Attachment(s): Dfs.zip

Comments

No Comments

Anonymous comments are disabled