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

NetDfsGetInfo (netapi32)
 
.
Summary
TODO - a short description

C# Signature:

[DllImport("Netapi32.dll", CharSet=CharSet.Unicode/*, SetLastError=true //Return value (NET_API_STATUS) contains error */)]
[DllImport("Netapi32.dll", CharSet=CharSet.Unicode, SetLastError=true)]
public static extern int NetDfsGetInfo(
    [MarshalAs(UnmanagedType.LPWStr)] string DfsEntryPath,    // DFS entry path for the volume
    [MarshalAs(UnmanagedType.LPWStr)] string ServerName,    // This parameter is currently ignored and should be NULL
    [MarshalAs(UnmanagedType.LPWStr)] string ShareName,    // This parameter is currently ignored and should be NULL.
    int Level,                        // Level of information requested
    out IntPtr Buffer                    // API allocates and returns buffer with requested info
    );

VB Signature:

<DllImport("Netapi32.dll", CharSet:=CharSet.Unicode, SetLastError:=True)> _
    Public Function NetDfsGetInfo( _
    <MarshalAs(UnmanagedType.LPWStr)> ByVal entryPath As String, _
    <MarshalAs(UnmanagedType.LPWStr)> ByVal serverName As String, _
    <MarshalAs(UnmanagedType.LPWStr)> ByVal shareName As String, _
    ByVal level As Integer, _
    ByRef buffer As IntPtr) As Integer

    End Function

User-Defined Types VB:

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)> _

    Public Structure DFS_INFO_3
    <MarshalAs(UnmanagedType.LPWStr)> Dim EntryPath As String
    <MarshalAs(UnmanagedType.LPWStr)> Dim Comment As String
    Dim State As UInt32
    Dim NumberOfStorages As UInt32
    Dim Storages As IntPtr
    End Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)> _

    Public Structure DFS_STORAGE_INFO
    Dim state As Int32
    <MarshalAs(UnmanagedType.LPWStr)> Dim ServerName As String
    <MarshalAs(UnmanagedType.LPWStr)> Dim ShareName As String
    End Structure

VB.NET Signature

Declare Unicode Function NetDfsGetInfo Lib "NETAPI32.DLL" (ByVal DfsEntryPath As String, ByVal ServerName As String, ByVal ShareName As String, ByVal Level As Integer, ByRef Buffer As IntPtr) As Integer

User-Defined Types VB.NET:

1):

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _

    Public Structure _DFS_INFO_3
    <MarshalAs(UnmanagedType.LPWStr)> Public EntryPath As String
    <MarshalAs(UnmanagedType.LPWStr)> Public Comment As String
    Public State As Int32
    Public NumberOfStorages As Int32
    Public storage As Int32
    End Structure

2):

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _

     Public Structure _DFS_STORAGE_INFO
    Public State As Integer
    <MarshalAs(UnmanagedType.LPWStr)> Public ServerName As String
    <MarshalAs(UnmanagedType.LPWStr)> Public ShareName As String
    End Structure

Notes:

[Stoyan Sabev] The function does not set the last error value, the error is returned directly and is NET_API_STATUS form

Tips & Tricks:

Remember to free buffer, see NetApiBufferFree

Sample Code C++:

static void Main(string[] args)
{
    IntPtr buf;
    if (args[0] != "")
    {
        int res=NetDfsGetInfo(args[0], null, null, 4, out buf);      
        if (res == 0)
        {
            try
            {
              DFS_INFO_4 info = (DFS_INFO_4)Marshal.PtrToStructure(buf, typeof(DFS_INFO_4));
              Console.WriteLine("{0}, {1}, {2} ", info.EntryPath, info.Comment, info.NumberOfStorages);
              for (int i = 0; i < info.NumberOfStorages; i++)
               {
                IntPtr pStorage = new IntPtr(info.Storage.ToInt64() + i * Marshal.SizeOf(typeof(DFS_STORAGE_INFO)));
                DFS_STORAGE_INFO storage = (DFS_STORAGE_INFO)Marshal.PtrToStructure(pStorage, typeof(DFS_STORAGE_INFO));
                Console.WriteLine("  {0}, {1}, {2} ", storage.ServerName, storage.ShareName, storage.State);
               }
            }
            finally
            {
              NetApiBufferFree(buf);
            }
        }
    }
}

Sample Code VB.NET:

Public Function DFSInfo(ByVal DfsEntryPath)

    Dim b As New _DFS_INFO_3
    Dim c As New _DFS_STORAGE_INFO
    Dim err_code As Integer
    Dim bufPtf As IntPtr
    Dim bufPtf2 As IntPtr

    err_code = NetDfsGetInfo(DfsEntryPath, vbNull, vbNull, 3, bufPtf)
    b = CType(Marshal.PtrToStructure(bufPtf, GetType(_DFS_INFO_3)), _DFS_INFO_3)
    bufPtf2 = b.storage

    For i As Integer = 0 To b.NumberOfStorages - 1
       'Increment the buffer and re-cast for each server in the list
       c = CType(Marshal.PtrToStructure(bufPtf2, GetType(_DFS_STORAGE_INFO)), _DFS_STORAGE_INFO)
       b.Storage += Marshal.SizeOf(c)
        bufPtf2 = b.Storage        
    Next

     NetApiBufferFree(bufPtf)

End Function

Alternative Managed API:

Do you know one? Please contribute it!

Documentation

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
Edit This Page
Find References
Show Printable Version
Revisions