NetDfsAdd (netapi32)
Last changed: -87.236.26.67

.
Summary
The NetDfsAdd function creates a new Distributed File System (Dfs) link or adds targets to an existing link in a Dfs root.

C# Signature:

[DllImport("Netapi32.dll", CharSet=CharSet.Auto, SetLastError=true)]
static extern int NetDfsAdd(
[MarshalAs(UnmanagedType.LPWStr)]
string DfsEntryPath,
[MarshalAs(UnmanagedType.LPWStr)]
string ServerName,
[MarshalAs(UnmanagedType.LPWStr)]
string PathName,
[MarshalAs(UnmanagedType.LPWStr)]
string Comment,
int Flags);

VB6 Signature:

Declare Function NetDfsAdd Lib "NETAPI32.DLL" (ByVal DfsEntryPath As String, ByVal ServerName As String, ByVal ShareName As String, ByVal Comment As String, ByVal Flags As Long) As Long

Go here for example code for VB6:

http://gethelp.devx.com/techtips/nt_pro/10_minute_solutions/10minNT0501-3.asp

VB.NET Signature:

Declare Function NetDfsAdd Lib "NETAPI32.DLL" (<Runtime.InteropServices.MarshalAs(Runtime.InteropServices.UnmanagedType.LPWStr)> ByVal DfsEntryPath As String, <Runtime.InteropServices.MarshalAs(Runtime.InteropServices.UnmanagedType.LPWStr)> ByVal ServerName As String, <Runtime.InteropServices.MarshalAs(Runtime.InteropServices.UnmanagedType.LPWStr)> ByVal ShareName As String, <Runtime.InteropServices.MarshalAs(Runtime.InteropServices.UnmanagedType.LPWStr)> ByVal Comment As String, ByVal Flags As Long) As Long

User-Defined Types:

None.

Notes:

The DFSEntryPath MUST have "\\" at the beginning. The ServerName conversely must NOT have "\\" at the beginning.

Tips & Tricks:

With a Flags value of 1, the call to NetDfsAdd will fail if the link (DFSEntryPath) already exists, even if the target (ServerName, PathName) is new. Use a Flags value of 0 to add multiple targets to the same DFS link.

Please add some!

Sample Code:

// DFS_ADD_VOLUME has a value of 1 - see MSDN docs
NetDfsAdd("\\DfsRoot\Path\Dir", "FileServer", "Share", "Comment", 1);

Alternative Managed API:

Do you know one? Please contribute it!

Documentation
NetDfsAdd on MSDN

Also on MSDN, there is a more detailed example of using this API:

http://msdn2.microsoft.com/en-us/library/aa380434.aspx