Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

NetDfsAdd (netapi32)
 
.
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 (DFS_ADD_VOLUME), 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

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Find References
Show Printable Version
Revisions